Skip to content

Commit 64280c8

Browse files
committed
V6.0.0
1 parent a467832 commit 64280c8

3 files changed

Lines changed: 55 additions & 12 deletions

File tree

pythonLogs/core/factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def create_logger(
309309
showlocation=final_config.showlocation,
310310
rotateatutc=final_config.rotateatutc,
311311
).init()
312-
case _ as unreachable:
312+
case _ as unreachable: # pragma: no cover
313313
assert_never(unreachable)
314314

315315
@staticmethod

tests/core/test_log_utils_windows.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def test_gzip_file_windows_retry_mechanism(self):
170170
file_handle.close()
171171

172172
# Mock time.sleep to verify retry mechanism
173-
with patch('pythonLogs.log_utils.time.sleep') as mock_sleep:
173+
with patch('pythonLogs.core.log_utils.time.sleep') as mock_sleep:
174174
# Mock open to raise PermissionError on first call, succeed on second
175175
call_count = 0
176176
original_open = open
@@ -186,8 +186,8 @@ def mock_open_side_effect(*args, real_open=original_open, **kwargs):
186186
return real_open(*args, **kwargs)
187187

188188
# Always mock platform as win32 and open with retry behavior
189-
with patch('pythonLogs.log_utils.sys.platform', 'win32'):
190-
with patch('pythonLogs.log_utils.open', side_effect=mock_open_side_effect):
189+
with patch('pythonLogs.core.log_utils.sys.platform', 'win32'):
190+
with patch('pythonLogs.core.log_utils.open', side_effect=mock_open_side_effect):
191191
result = log_utils.gzip_file_with_sufix(file_path, "retry_test")
192192

193193
# Verify retry was attempted (sleep was called)
@@ -505,9 +505,9 @@ def mock_open_side_effect(*args, **kwargs):
505505
return original_open(*args, **kwargs)
506506

507507
# Mock sys.platform to be Windows and time.sleep to verify retry
508-
with unittest.mock.patch('pythonLogs.log_utils.sys.platform', 'win32'):
509-
with unittest.mock.patch('pythonLogs.log_utils.time.sleep') as mock_sleep:
510-
with unittest.mock.patch('pythonLogs.log_utils.open', side_effect=mock_open_side_effect):
508+
with unittest.mock.patch('pythonLogs.core.log_utils.sys.platform', 'win32'):
509+
with unittest.mock.patch('pythonLogs.core.log_utils.time.sleep') as mock_sleep:
510+
with unittest.mock.patch('pythonLogs.core.log_utils.open', side_effect=mock_open_side_effect):
511511
result = log_utils.gzip_file_with_sufix(file_path, "comprehensive_retry")
512512

513513
# Verify retries were attempted (sleep should be called twice)

tests/factory/test_factory.py

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,10 @@ def test_factory_ensure_initialized_behavior(self):
315315
LoggerFactory._ensure_initialized()
316316
assert LoggerFactory._initialized is True
317317

318-
def test_factory_atexit_cleanup_error_handling(self):
319-
"""Test atexit cleanup error handling."""
320-
321-
# Mock the clear_registry method to raise an expected error type
322-
with patch.object(LoggerFactory, 'clear_registry', side_effect=OSError("Test error")):
318+
@pytest.mark.parametrize("error_type", [OSError, ValueError, RuntimeError])
319+
def test_factory_atexit_cleanup_error_handling(self, error_type):
320+
"""Test atexit cleanup handles expected exceptions gracefully."""
321+
with patch.object(LoggerFactory, 'clear_registry', side_effect=error_type("Test error")):
323322
# Should not raise an exception (silently ignored)
324323
LoggerFactory._atexit_cleanup()
325324

@@ -449,3 +448,47 @@ def test_factory_large_scale_operations(self):
449448
for logger in created_loggers:
450449
logger.info("Scale test message")
451450
assert logger.name is not None
451+
452+
def test_factory_get_memory_limits(self):
453+
"""Test get_memory_limits returns current settings."""
454+
# Set specific limits
455+
LoggerFactory.set_memory_limits(max_loggers=75, ttl_seconds=2400)
456+
457+
# Get and verify limits
458+
limits = LoggerFactory.get_memory_limits()
459+
assert limits['max_loggers'] == 75
460+
assert limits['ttl_seconds'] == 2400
461+
462+
@pytest.mark.skipif(
463+
sys.platform == "win32",
464+
reason="Windows file locking issues with TemporaryDirectory - see test_factory_windows.py",
465+
)
466+
def test_timed_rotating_log_context_manager(self):
467+
"""Test TimedRotatingLog context manager __enter__ and __exit__."""
468+
with tempfile.TemporaryDirectory() as temp_dir:
469+
with TimedRotatingLog(
470+
name="context_timed_test",
471+
directory=temp_dir,
472+
when="midnight",
473+
level="INFO",
474+
) as logger:
475+
logger.info("Message inside context manager")
476+
assert logger.name == "context_timed_test"
477+
# Logger should be cleaned up after exiting context
478+
479+
def test_shutdown_logger_convenience_function(self):
480+
"""Test shutdown_logger convenience function."""
481+
from pythonLogs.core.factory import shutdown_logger
482+
483+
# Create and register a logger
484+
LoggerFactory.get_or_create_logger(LoggerType.BASIC, name="shutdown_conv_test")
485+
assert "shutdown_conv_test" in get_registered_loggers()
486+
487+
# Shutdown via convenience function
488+
result = shutdown_logger("shutdown_conv_test")
489+
assert result is True
490+
assert "shutdown_conv_test" not in get_registered_loggers()
491+
492+
# Try shutting down non-existent logger
493+
result = shutdown_logger("non_existent_conv")
494+
assert result is False

0 commit comments

Comments
 (0)