Run ruff format changes and finalize indentation and lint fixes.
This commit is contained in:
@@ -6,10 +6,7 @@ import logging
|
||||
import pytest
|
||||
from unittest.mock import patch
|
||||
|
||||
import sys
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))
|
||||
|
||||
from src.logger import init_logger
|
||||
from thechart.core.logger import init_logger
|
||||
|
||||
|
||||
class TestLogger:
|
||||
@@ -17,7 +14,7 @@ class TestLogger:
|
||||
|
||||
def test_init_logger_basic(self, temp_log_dir):
|
||||
"""Test basic logger initialization."""
|
||||
with patch('logger.LOG_PATH', temp_log_dir):
|
||||
with patch('thechart.core.logger.LOG_PATH', temp_log_dir):
|
||||
logger = init_logger("test_logger", testing_mode=False)
|
||||
|
||||
assert isinstance(logger, logging.Logger)
|
||||
@@ -26,21 +23,21 @@ class TestLogger:
|
||||
|
||||
def test_init_logger_testing_mode(self, temp_log_dir):
|
||||
"""Test logger initialization in testing mode."""
|
||||
with patch('logger.LOG_PATH', temp_log_dir):
|
||||
with patch('thechart.core.logger.LOG_PATH', temp_log_dir):
|
||||
logger = init_logger("test_logger", testing_mode=True)
|
||||
|
||||
assert logger.level == logging.DEBUG
|
||||
|
||||
def test_init_logger_production_mode(self, temp_log_dir):
|
||||
"""Test logger initialization in production mode."""
|
||||
with patch('logger.LOG_PATH', temp_log_dir):
|
||||
with patch('thechart.core.logger.LOG_PATH', temp_log_dir):
|
||||
logger = init_logger("test_logger", testing_mode=False)
|
||||
|
||||
assert logger.level == logging.INFO
|
||||
|
||||
def test_file_handlers_created(self, temp_log_dir):
|
||||
"""Test that file handlers are created correctly."""
|
||||
with patch('logger.LOG_PATH', temp_log_dir):
|
||||
with patch('thechart.core.logger.LOG_PATH', temp_log_dir):
|
||||
logger = init_logger("test_logger", testing_mode=False)
|
||||
|
||||
# Check that handlers were added
|
||||
@@ -48,7 +45,7 @@ class TestLogger:
|
||||
|
||||
def test_file_handler_levels(self, temp_log_dir):
|
||||
"""Test that file handlers have correct log levels."""
|
||||
with patch('logger.LOG_PATH', temp_log_dir):
|
||||
with patch('thechart.core.logger.LOG_PATH', temp_log_dir):
|
||||
logger = init_logger("test_logger", testing_mode=False)
|
||||
|
||||
handler_levels = [handler.level for handler in logger.handlers if isinstance(handler, logging.FileHandler)]
|
||||
@@ -60,7 +57,7 @@ class TestLogger:
|
||||
|
||||
def test_log_file_paths(self, temp_log_dir):
|
||||
"""Test that log files are created with correct paths."""
|
||||
with patch('logger.LOG_PATH', temp_log_dir):
|
||||
with patch('thechart.core.logger.LOG_PATH', temp_log_dir):
|
||||
logger = init_logger("test_logger", testing_mode=False)
|
||||
|
||||
# Log something to trigger file creation
|
||||
@@ -70,9 +67,9 @@ class TestLogger:
|
||||
|
||||
# Check that log files would be created (paths are correct)
|
||||
expected_files = [
|
||||
os.path.join(temp_log_dir, "app.log"),
|
||||
os.path.join(temp_log_dir, "app.warning.log"),
|
||||
os.path.join(temp_log_dir, "app.error.log")
|
||||
os.path.join(temp_log_dir, "thechart.log"),
|
||||
os.path.join(temp_log_dir, "thechart.warning.log"),
|
||||
os.path.join(temp_log_dir, "thechart.error.log")
|
||||
]
|
||||
|
||||
# The files should exist or be ready to be created
|
||||
@@ -82,7 +79,7 @@ class TestLogger:
|
||||
|
||||
def test_formatter_format(self, temp_log_dir):
|
||||
"""Test that formatters are set correctly."""
|
||||
with patch('logger.LOG_PATH', temp_log_dir):
|
||||
with patch('thechart.core.logger.LOG_PATH', temp_log_dir):
|
||||
logger = init_logger("test_logger", testing_mode=False)
|
||||
|
||||
expected_format = "%(asctime)s - %(name)s - %(funcName)s - %(levelname)s - %(message)s"
|
||||
@@ -94,7 +91,7 @@ class TestLogger:
|
||||
@patch('colorlog.basicConfig')
|
||||
def test_colorlog_configuration(self, mock_basicConfig, temp_log_dir):
|
||||
"""Test that colorlog is configured correctly."""
|
||||
with patch('logger.LOG_PATH', temp_log_dir):
|
||||
with patch('thechart.core.logger.LOG_PATH', temp_log_dir):
|
||||
init_logger("test_logger", testing_mode=False)
|
||||
|
||||
mock_basicConfig.assert_called_once()
|
||||
@@ -108,7 +105,7 @@ class TestLogger:
|
||||
|
||||
def test_multiple_logger_instances(self, temp_log_dir):
|
||||
"""Test creating multiple logger instances."""
|
||||
with patch('logger.LOG_PATH', temp_log_dir):
|
||||
with patch('thechart.core.logger.LOG_PATH', temp_log_dir):
|
||||
logger1 = init_logger("logger1", testing_mode=False)
|
||||
logger2 = init_logger("logger2", testing_mode=True)
|
||||
|
||||
@@ -119,7 +116,7 @@ class TestLogger:
|
||||
|
||||
def test_logger_inheritance(self, temp_log_dir):
|
||||
"""Test that logger follows Python logging hierarchy."""
|
||||
with patch('logger.LOG_PATH', temp_log_dir):
|
||||
with patch('thechart.core.logger.LOG_PATH', temp_log_dir):
|
||||
logger = init_logger("test.module.logger", testing_mode=False)
|
||||
|
||||
assert logger.name == "test.module.logger"
|
||||
@@ -129,7 +126,7 @@ class TestLogger:
|
||||
"""Test error handling when file handler creation fails."""
|
||||
mock_file_handler.side_effect = PermissionError("Cannot create log file")
|
||||
|
||||
with patch('logger.LOG_PATH', temp_log_dir):
|
||||
with patch('thechart.core.logger.LOG_PATH', temp_log_dir):
|
||||
# Should not raise an exception, but handle gracefully
|
||||
try:
|
||||
logger = init_logger("test_logger", testing_mode=False)
|
||||
@@ -140,7 +137,7 @@ class TestLogger:
|
||||
|
||||
def test_logger_name_parameter(self, temp_log_dir):
|
||||
"""Test that logger name is set correctly from parameter."""
|
||||
with patch('logger.LOG_PATH', temp_log_dir):
|
||||
with patch('thechart.core.logger.LOG_PATH', temp_log_dir):
|
||||
test_name = "my.custom.logger.name"
|
||||
logger = init_logger(test_name, testing_mode=False)
|
||||
|
||||
@@ -148,7 +145,7 @@ class TestLogger:
|
||||
|
||||
def test_testing_mode_boolean(self, temp_log_dir):
|
||||
"""Test that testing_mode parameter accepts boolean values."""
|
||||
with patch('logger.LOG_PATH', temp_log_dir):
|
||||
with patch('thechart.core.logger.LOG_PATH', temp_log_dir):
|
||||
logger_true = init_logger("test1", testing_mode=True)
|
||||
logger_false = init_logger("test2", testing_mode=False)
|
||||
|
||||
@@ -157,7 +154,7 @@ class TestLogger:
|
||||
|
||||
def test_log_format_contains_required_fields(self, temp_log_dir):
|
||||
"""Test that log format contains all required fields."""
|
||||
with patch('logger.LOG_PATH', temp_log_dir):
|
||||
with patch('thechart.core.logger.LOG_PATH', temp_log_dir):
|
||||
logger = init_logger("test_logger", testing_mode=False)
|
||||
|
||||
log_format = "%(asctime)s - %(name)s - %(funcName)s - %(levelname)s - %(message)s"
|
||||
@@ -169,7 +166,7 @@ class TestLogger:
|
||||
|
||||
def test_handler_file_mode(self, temp_log_dir):
|
||||
"""Test that file handlers use append mode by default."""
|
||||
with patch('logger.LOG_PATH', temp_log_dir):
|
||||
with patch('thechart.core.logger.LOG_PATH', temp_log_dir):
|
||||
logger = init_logger("test_logger", testing_mode=False)
|
||||
|
||||
# File handlers should be in append mode by default
|
||||
|
||||
Reference in New Issue
Block a user