Files
thechart/tests/test_init.py

35 lines
1.6 KiB
Python

"""
Canonical replacements for legacy init tests, targeting thechart.core.logger.
"""
import os
from unittest.mock import patch
class TestInitCanonical:
def test_loggers_write_mode_respects_log_clear(self, temp_log_dir):
from thechart.core.logger import init_logger
with patch('thechart.core.logger.LOG_PATH', temp_log_dir), \
patch('thechart.core.logger.LOG_CLEAR', 'True'):
logger = init_logger('init', testing_mode=False)
assert any(hasattr(h, 'stream') for h in logger.handlers)
def test_testing_mode_flag(self, temp_log_dir):
from thechart.core.logger import init_logger
with patch('thechart.core.logger.LOG_PATH', temp_log_dir):
assert init_logger('init', testing_mode=True).level == 10 # DEBUG
assert init_logger('init', testing_mode=False).level in (20, 30, 40, 50)
def test_log_file_paths(self, temp_log_dir):
from thechart.core.logger import init_logger
with patch('thechart.core.logger.LOG_PATH', temp_log_dir):
logger = init_logger('init', testing_mode=False)
# Touch files via logging
logger.debug("d"); logger.warning("w"); logger.error("e")
expected = {
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'),
}
actual = {getattr(h, 'baseFilename', None) for h in logger.handlers if hasattr(h, 'baseFilename')}
assert expected.issubset(actual)