File size: 1,493 Bytes
1fed057
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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()