@@ -65,15 +65,17 @@ def test_init_loggers_console_enabled():
6565 """Test that init_loggers works with console enabled."""
6666 # Call init_loggers with console enabled (CLI mode)
6767 init_loggers (enable_console = True , log_level = "INFO" )
68-
68+
6969 logger = logging .getLogger ("graphrag" )
70-
70+
7171 # Should have both a console handler and a file handler (default config)
72- console_handlers = [h for h in logger .handlers if isinstance (h , logging .StreamHandler )]
72+ console_handlers = [
73+ h for h in logger .handlers if isinstance (h , logging .StreamHandler )
74+ ]
7375 file_handlers = [h for h in logger .handlers if isinstance (h , logging .FileHandler )]
7476 assert len (console_handlers ) > 0
7577 assert len (file_handlers ) > 0 # Due to default file config
76-
78+
7779 # Clean up
7880 for handler in logger .handlers [:]:
7981 if isinstance (handler , logging .FileHandler ):
@@ -86,25 +88,27 @@ def test_init_loggers_default_config():
8688 with tempfile .TemporaryDirectory () as temp_dir :
8789 # Call init_loggers with no config (should default to file logging)
8890 init_loggers (root_dir = temp_dir , log_level = "INFO" )
89-
91+
9092 logger = logging .getLogger ("graphrag" )
91-
93+
9294 # Should have a file handler due to default config
93- file_handlers = [h for h in logger .handlers if isinstance (h , logging .FileHandler )]
95+ file_handlers = [
96+ h for h in logger .handlers if isinstance (h , logging .FileHandler )
97+ ]
9498 assert len (file_handlers ) > 0
95-
99+
96100 # Test logging works
97101 test_message = "Test default config message"
98102 logger .info (test_message )
99-
103+
100104 # Check that the log file was created with default structure
101105 log_file = Path (temp_dir ) / "logs" / "logs.txt"
102106 assert log_file .exists ()
103-
107+
104108 with open (log_file ) as f :
105109 content = f .read ()
106110 assert test_message in content
107-
111+
108112 # Clean up
109113 for handler in logger .handlers [:]:
110114 if isinstance (handler , logging .FileHandler ):
@@ -115,32 +119,31 @@ def test_init_loggers_default_config():
115119def test_init_loggers_file_config ():
116120 """Test that init_loggers works with file configuration."""
117121 with tempfile .TemporaryDirectory () as temp_dir :
118- config = ReportingConfig (
119- type = ReportingType .file ,
120- base_dir = "logs"
121- )
122-
122+ config = ReportingConfig (type = ReportingType .file , base_dir = "logs" )
123+
123124 # Call init_loggers with file config
124125 init_loggers (config = config , root_dir = temp_dir , log_level = "INFO" )
125-
126+
126127 logger = logging .getLogger ("graphrag" )
127-
128+
128129 # Should have a file handler
129- file_handlers = [h for h in logger .handlers if isinstance (h , logging .FileHandler )]
130+ file_handlers = [
131+ h for h in logger .handlers if isinstance (h , logging .FileHandler )
132+ ]
130133 assert len (file_handlers ) > 0
131-
134+
132135 # Test logging works
133136 test_message = "Test init_loggers file message"
134137 logger .info (test_message )
135-
138+
136139 # Check that the log file was created
137140 log_file = Path (temp_dir ) / "logs" / "logs.txt"
138141 assert log_file .exists ()
139-
142+
140143 with open (log_file ) as f :
141144 content = f .read ()
142145 assert test_message in content
143-
146+
144147 # Clean up
145148 for handler in logger .handlers [:]:
146149 if isinstance (handler , logging .FileHandler ):
@@ -151,32 +154,36 @@ def test_init_loggers_file_config():
151154def test_init_loggers_console_config ():
152155 """Test that init_loggers works with console configuration."""
153156 config = ReportingConfig (type = ReportingType .console )
154-
157+
155158 # Call init_loggers with console config but no enable_console
156159 init_loggers (config = config , log_level = "INFO" , enable_console = False )
157-
160+
158161 logger = logging .getLogger ("graphrag" )
159-
162+
160163 # Should have a console handler from the config
161- console_handlers = [h for h in logger .handlers if isinstance (h , logging .StreamHandler )]
164+ console_handlers = [
165+ h for h in logger .handlers if isinstance (h , logging .StreamHandler )
166+ ]
162167 assert len (console_handlers ) > 0
163-
168+
164169 # Clean up
165170 logger .handlers .clear ()
166171
167172
168173def test_init_loggers_both_console ():
169174 """Test that init_loggers doesn't duplicate console handlers."""
170175 config = ReportingConfig (type = ReportingType .console )
171-
176+
172177 # Call init_loggers with both console config and enable_console=True
173178 init_loggers (config = config , log_level = "INFO" , enable_console = True )
174-
179+
175180 logger = logging .getLogger ("graphrag" )
176-
181+
177182 # Should have only one console handler (no duplicates)
178- console_handlers = [h for h in logger .handlers if isinstance (h , logging .StreamHandler )]
183+ console_handlers = [
184+ h for h in logger .handlers if isinstance (h , logging .StreamHandler )
185+ ]
179186 assert len (console_handlers ) == 1
180-
187+
181188 # Clean up
182189 logger .handlers .clear ()
0 commit comments