feat(v0.1.0): project foundation with logging and config
This commit is contained in:
83
tests/unit/test_logging/test_logger.py
Normal file
83
tests/unit/test_logging/test_logger.py
Normal file
@@ -0,0 +1,83 @@
|
||||
"""Tests for logging system."""
|
||||
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from src.core.exceptions import ConfigurationError
|
||||
from src.logging import get_logger
|
||||
|
||||
|
||||
def test_get_logger_with_name():
|
||||
"""Test getting logger with name."""
|
||||
logger = get_logger("test_module")
|
||||
assert isinstance(logger, logging.Logger)
|
||||
assert logger.name == "test_module"
|
||||
|
||||
|
||||
def test_get_logger_root():
|
||||
"""Test getting root logger."""
|
||||
logger = get_logger()
|
||||
assert isinstance(logger, logging.Logger)
|
||||
|
||||
|
||||
def test_logger_logs_message(caplog):
|
||||
"""Test that logger actually logs messages."""
|
||||
logger = get_logger("test")
|
||||
logger.info("Test message")
|
||||
assert "Test message" in caplog.text
|
||||
|
||||
|
||||
def test_logger_with_missing_config(temp_dir, monkeypatch):
|
||||
"""Test logger with missing config file."""
|
||||
# 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
|
||||
|
||||
|
||||
def test_logger_creates_directories(temp_dir, monkeypatch):
|
||||
"""Test that logger creates log directories."""
|
||||
from src.core import constants
|
||||
original_path = constants.PATHS["logs"]
|
||||
constants.PATHS["logs"] = temp_dir / "logs"
|
||||
|
||||
# Create minimal config
|
||||
config_dir = temp_dir / "config"
|
||||
config_dir.mkdir()
|
||||
logging_config = config_dir / "logging.yaml"
|
||||
logging_config.write_text(
|
||||
"""
|
||||
version: 1
|
||||
disable_existing_loggers: false
|
||||
|
||||
formatters:
|
||||
detailed:
|
||||
format: '%(message)s'
|
||||
|
||||
handlers:
|
||||
console:
|
||||
class: logging.StreamHandler
|
||||
level: INFO
|
||||
formatter: detailed
|
||||
|
||||
root:
|
||||
level: INFO
|
||||
handlers:
|
||||
- console
|
||||
"""
|
||||
)
|
||||
|
||||
logger = get_logger("test")
|
||||
assert isinstance(logger, logging.Logger)
|
||||
|
||||
# Restore original path
|
||||
constants.PATHS["logs"] = original_path
|
||||
|
||||
Reference in New Issue
Block a user