@@ -190,27 +190,17 @@ def cli_runner():
190190 return CliRunner ()
191191
192192
193- @pytest .fixture
194- def mock_logging (mocker ):
195- return mocker .patch ("your_cli_module.structlog.get_logger" )
196-
197-
198- @pytest .fixture
199- def mock_setup_logging (mocker ):
200- return mocker .patch ("your_cli_module.setup_logging" )
201-
202-
203193def test_serve_default_options (cli_runner ):
204194 """Test serve command with default options."""
205195 # Use patches for run_servers and logging setup
206196 with (
207197 patch ("src.codegate.cli.run_servers" ) as mock_run ,
208- patch ("src.codegate.cli.structlog.get_logger " ) as mock_logging ,
198+ patch ("src.codegate.cli.OriginLogger " ) as mock_origin_logger ,
209199 patch ("src.codegate.cli.setup_logging" ) as mock_setup_logging ,
210200 ):
211201
212202 logger_instance = MagicMock ()
213- mock_logging .return_value = logger_instance
203+ mock_origin_logger .return_value = logger_instance
214204
215205 # Invoke the CLI command
216206 result = cli_runner .invoke (cli , ["serve" ])
@@ -222,7 +212,7 @@ def test_serve_default_options(cli_runner):
222212 mock_setup_logging .assert_called_once_with (LogLevel .INFO , LogFormat .JSON )
223213
224214 # Check if logging was done correctly
225- mock_logging .assert_called_with ("codegate " )
215+ mock_origin_logger .assert_called_with ("cli " )
226216
227217 # Validate run_servers was called once
228218 mock_run .assert_called_once ()
@@ -232,12 +222,12 @@ def test_serve_custom_options(cli_runner):
232222 """Test serve command with custom options."""
233223 with (
234224 patch ("src.codegate.cli.run_servers" ) as mock_run ,
235- patch ("src.codegate.cli.structlog.get_logger " ) as mock_logging ,
225+ patch ("src.codegate.cli.OriginLogger " ) as mock_origin_logger ,
236226 patch ("src.codegate.cli.setup_logging" ) as mock_setup_logging ,
237227 ):
238228
239229 logger_instance = MagicMock ()
240- mock_logging .return_value = logger_instance
230+ mock_origin_logger .return_value = logger_instance
241231
242232 # Invoke the CLI command with custom options
243233 result = cli_runner .invoke (
@@ -272,7 +262,7 @@ def test_serve_custom_options(cli_runner):
272262 mock_setup_logging .assert_called_once_with (LogLevel .DEBUG , LogFormat .TEXT )
273263
274264 # Assert logger got called with the expected module name
275- mock_logging .assert_called_with ("codegate " )
265+ mock_origin_logger .assert_called_with ("cli " )
276266
277267 # Validate run_servers was called once
278268 mock_run .assert_called_once ()
@@ -332,20 +322,20 @@ def test_serve_with_config_file(cli_runner, temp_config_file):
332322 """Test serve command with config file."""
333323 with (
334324 patch ("src.codegate.cli.run_servers" ) as mock_run ,
335- patch ("src.codegate.cli.structlog.get_logger " ) as mock_logging ,
325+ patch ("src.codegate.cli.OriginLogger " ) as mock_origin_logger ,
336326 patch ("src.codegate.cli.setup_logging" ) as mock_setup_logging ,
337327 ):
338328
339329 logger_instance = MagicMock ()
340- mock_logging .return_value = logger_instance
330+ mock_origin_logger .return_value = logger_instance
341331
342332 # Invoke the CLI command with the configuration file
343333 result = cli_runner .invoke (cli , ["serve" , "--config" , str (temp_config_file )])
344334
345335 # Assertions to ensure the CLI ran successfully
346336 assert result .exit_code == 0
347337 mock_setup_logging .assert_called_once_with (LogLevel .DEBUG , LogFormat .JSON )
348- mock_logging .assert_called_with ("codegate " )
338+ mock_origin_logger .assert_called_with ("cli " )
349339
350340 # Validate that run_servers was called with the expected configuration
351341 mock_run .assert_called_once ()
@@ -380,12 +370,12 @@ def test_serve_priority_resolution(cli_runner: CliRunner, temp_config_file: Path
380370 with (
381371 patch .dict (os .environ , {"LOG_LEVEL" : "INFO" , "PORT" : "9999" }, clear = True ),
382372 patch ("src.codegate.cli.run_servers" ) as mock_run ,
383- patch ("src.codegate.cli.structlog.get_logger " ) as mock_logging ,
373+ patch ("src.codegate.cli.OriginLogger " ) as mock_origin_logger ,
384374 patch ("src.codegate.cli.setup_logging" ) as mock_setup_logging ,
385375 ):
386376 # Set up mock logger
387377 logger_instance = MagicMock ()
388- mock_logging .return_value = logger_instance
378+ mock_origin_logger .return_value = logger_instance
389379
390380 # Execute CLI command with specific options overriding environment and config file settings
391381 result = cli_runner .invoke (
@@ -420,7 +410,7 @@ def test_serve_priority_resolution(cli_runner: CliRunner, temp_config_file: Path
420410
421411 # Ensure logging setup was called with the highest priority settings (CLI arguments)
422412 mock_setup_logging .assert_called_once_with ("ERROR" , "TEXT" )
423- mock_logging .assert_called_with ("codegate " )
413+ mock_origin_logger .assert_called_with ("cli " )
424414
425415 # Verify that the run_servers was called with the overridden settings
426416 config_arg = mock_run .call_args [0 ][0 ] # Assuming Config is the first positional arg
@@ -448,12 +438,12 @@ def test_serve_certificate_options(cli_runner: CliRunner) -> None:
448438 """Test serve command with certificate options."""
449439 with (
450440 patch ("src.codegate.cli.run_servers" ) as mock_run ,
451- patch ("src.codegate.cli.structlog.get_logger " ) as mock_logging ,
441+ patch ("src.codegate.cli.OriginLogger " ) as mock_origin_logger ,
452442 patch ("src.codegate.cli.setup_logging" ) as mock_setup_logging ,
453443 ):
454444 # Set up mock logger
455445 logger_instance = MagicMock ()
456- mock_logging .return_value = logger_instance
446+ mock_origin_logger .return_value = logger_instance
457447
458448 # Execute CLI command with certificate options
459449 result = cli_runner .invoke (
@@ -478,7 +468,7 @@ def test_serve_certificate_options(cli_runner: CliRunner) -> None:
478468
479469 # Ensure logging setup was called with expected arguments
480470 mock_setup_logging .assert_called_once_with ("INFO" , "JSON" )
481- mock_logging .assert_called_with ("codegate " )
471+ mock_origin_logger .assert_called_with ("cli " )
482472
483473 # Verify that run_servers was called with the provided certificate options
484474 config_arg = mock_run .call_args [0 ][0 ] # Assuming Config is the first positional arg
0 commit comments