import os import sys import unittest from pathlib import Path # Add the project root to the Python path sys.path.insert(0, str(Path(__file__).parent.parent)) from src.utils.logging import get_logger class TestLogging(unittest.TestCase): """Test the logging functionality.""" def test_logger_creation(self): """Test that the logger can be created and used.""" logger = get_logger() self.assertIsNotNone(logger) # Test different log levels logger.debug("This is a debug message") logger.info("This is an info message") logger.warning("This is a warning message") logger.error("This is an error message") # Check that the logs directory was created logs_dir = Path(__file__).parent.parent / 'logs' self.assertTrue(logs_dir.exists()) # Check that at least one log file was created log_files = list(logs_dir.glob('*.log')) self.assertGreater(len(log_files), 0) # Check that the log file contains the test messages with open(log_files[0], 'r') as f: log_content = f.read() self.assertIn("This is an info message", log_content) self.assertIn("This is a warning message", log_content) self.assertIn("This is an error message", log_content) # Debug messages might not be in the log file if the level is set to INFO if __name__ == '__main__': unittest.main()