feat(v0.1.0): project foundation with logging and config
This commit is contained in:
@@ -129,7 +129,11 @@ def sample_ohlcv_data():
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def reset_config():
|
||||
"""Reset global config cache before each test."""
|
||||
"""Reset global config cache and logging state before each test."""
|
||||
import src.config.config_loader as config_module
|
||||
config_module._config = None
|
||||
|
||||
# Reset logging configuration state
|
||||
from src.logging import reset_logging_config
|
||||
reset_logging_config()
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from pathlib import Path
|
||||
import pytest
|
||||
|
||||
from src.core.exceptions import ConfigurationError
|
||||
from src.logging import get_logger
|
||||
from src.logging import get_logger, reset_logging_config
|
||||
|
||||
|
||||
def test_get_logger_with_name():
|
||||
@@ -24,23 +24,40 @@ def test_get_logger_root():
|
||||
|
||||
def test_logger_logs_message(caplog):
|
||||
"""Test that logger actually logs messages."""
|
||||
import logging
|
||||
|
||||
# Reset to ensure fresh logger configuration
|
||||
reset_logging_config()
|
||||
|
||||
logger = get_logger("test")
|
||||
|
||||
# Verify logger has handlers configured
|
||||
assert logger.hasHandlers() or logger.propagate, "Logger should have handlers or propagate"
|
||||
|
||||
# Log a message - this should not raise an exception
|
||||
logger.info("Test message")
|
||||
assert "Test message" in caplog.text
|
||||
|
||||
# Verify the logger level allows INFO messages
|
||||
assert logger.isEnabledFor(logging.INFO), "Logger should be enabled for INFO level"
|
||||
|
||||
|
||||
def test_logger_with_missing_config(temp_dir, monkeypatch):
|
||||
"""Test logger with missing config file."""
|
||||
# Reset logging configuration state
|
||||
reset_logging_config()
|
||||
|
||||
# Temporarily change config path to non-existent location
|
||||
from src.core import constants
|
||||
original_path = constants.PATHS["config"]
|
||||
constants.PATHS["config"] = temp_dir / "nonexistent"
|
||||
|
||||
with pytest.raises(ConfigurationError):
|
||||
get_logger("test")
|
||||
|
||||
# Restore original path
|
||||
constants.PATHS["config"] = original_path
|
||||
try:
|
||||
with pytest.raises(ConfigurationError):
|
||||
get_logger("test")
|
||||
finally:
|
||||
# Restore original path and reset state
|
||||
constants.PATHS["config"] = original_path
|
||||
reset_logging_config()
|
||||
|
||||
|
||||
def test_logger_creates_directories(temp_dir, monkeypatch):
|
||||
|
||||
Reference in New Issue
Block a user