@@ -190,28 +190,13 @@ def cli_runner():
190
190
return CliRunner ()
191
191
192
192
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
-
203
193
def test_serve_default_options (cli_runner ):
204
194
"""Test serve command with default options."""
205
195
# Use patches for run_servers and logging setup
206
196
with (
207
197
patch ("src.codegate.cli.run_servers" ) as mock_run ,
208
- patch ("src.codegate.cli.structlog.get_logger" ) as mock_logging ,
209
198
patch ("src.codegate.cli.setup_logging" ) as mock_setup_logging ,
210
199
):
211
-
212
- logger_instance = MagicMock ()
213
- mock_logging .return_value = logger_instance
214
-
215
200
# Invoke the CLI command
216
201
result = cli_runner .invoke (cli , ["serve" ])
217
202
@@ -221,9 +206,6 @@ def test_serve_default_options(cli_runner):
221
206
# Check if the logging setup was called with expected defaults
222
207
mock_setup_logging .assert_called_once_with (LogLevel .INFO , LogFormat .JSON )
223
208
224
- # Check if logging was done correctly
225
- mock_logging .assert_called_with ("codegate" )
226
-
227
209
# Validate run_servers was called once
228
210
mock_run .assert_called_once ()
229
211
@@ -232,13 +214,8 @@ def test_serve_custom_options(cli_runner):
232
214
"""Test serve command with custom options."""
233
215
with (
234
216
patch ("src.codegate.cli.run_servers" ) as mock_run ,
235
- patch ("src.codegate.cli.structlog.get_logger" ) as mock_logging ,
236
217
patch ("src.codegate.cli.setup_logging" ) as mock_setup_logging ,
237
218
):
238
-
239
- logger_instance = MagicMock ()
240
- mock_logging .return_value = logger_instance
241
-
242
219
# Invoke the CLI command with custom options
243
220
result = cli_runner .invoke (
244
221
cli ,
@@ -271,9 +248,6 @@ def test_serve_custom_options(cli_runner):
271
248
# Assert logging setup was called with the provided log level and format
272
249
mock_setup_logging .assert_called_once_with (LogLevel .DEBUG , LogFormat .TEXT )
273
250
274
- # Assert logger got called with the expected module name
275
- mock_logging .assert_called_with ("codegate" )
276
-
277
251
# Validate run_servers was called once
278
252
mock_run .assert_called_once ()
279
253
# Retrieve the actual Config object passed to run_servers
@@ -332,20 +306,14 @@ def test_serve_with_config_file(cli_runner, temp_config_file):
332
306
"""Test serve command with config file."""
333
307
with (
334
308
patch ("src.codegate.cli.run_servers" ) as mock_run ,
335
- patch ("src.codegate.cli.structlog.get_logger" ) as mock_logging ,
336
309
patch ("src.codegate.cli.setup_logging" ) as mock_setup_logging ,
337
310
):
338
-
339
- logger_instance = MagicMock ()
340
- mock_logging .return_value = logger_instance
341
-
342
311
# Invoke the CLI command with the configuration file
343
312
result = cli_runner .invoke (cli , ["serve" , "--config" , str (temp_config_file )])
344
313
345
314
# Assertions to ensure the CLI ran successfully
346
315
assert result .exit_code == 0
347
316
mock_setup_logging .assert_called_once_with (LogLevel .DEBUG , LogFormat .JSON )
348
- mock_logging .assert_called_with ("codegate" )
349
317
350
318
# Validate that run_servers was called with the expected configuration
351
319
mock_run .assert_called_once ()
@@ -380,13 +348,8 @@ def test_serve_priority_resolution(cli_runner: CliRunner, temp_config_file: Path
380
348
with (
381
349
patch .dict (os .environ , {"LOG_LEVEL" : "INFO" , "PORT" : "9999" }, clear = True ),
382
350
patch ("src.codegate.cli.run_servers" ) as mock_run ,
383
- patch ("src.codegate.cli.structlog.get_logger" ) as mock_logging ,
384
351
patch ("src.codegate.cli.setup_logging" ) as mock_setup_logging ,
385
352
):
386
- # Set up mock logger
387
- logger_instance = MagicMock ()
388
- mock_logging .return_value = logger_instance
389
-
390
353
# Execute CLI command with specific options overriding environment and config file settings
391
354
result = cli_runner .invoke (
392
355
cli ,
@@ -420,7 +383,6 @@ def test_serve_priority_resolution(cli_runner: CliRunner, temp_config_file: Path
420
383
421
384
# Ensure logging setup was called with the highest priority settings (CLI arguments)
422
385
mock_setup_logging .assert_called_once_with ("ERROR" , "TEXT" )
423
- mock_logging .assert_called_with ("codegate" )
424
386
425
387
# Verify that the run_servers was called with the overridden settings
426
388
config_arg = mock_run .call_args [0 ][0 ] # Assuming Config is the first positional arg
@@ -448,13 +410,8 @@ def test_serve_certificate_options(cli_runner: CliRunner) -> None:
448
410
"""Test serve command with certificate options."""
449
411
with (
450
412
patch ("src.codegate.cli.run_servers" ) as mock_run ,
451
- patch ("src.codegate.cli.structlog.get_logger" ) as mock_logging ,
452
413
patch ("src.codegate.cli.setup_logging" ) as mock_setup_logging ,
453
414
):
454
- # Set up mock logger
455
- logger_instance = MagicMock ()
456
- mock_logging .return_value = logger_instance
457
-
458
415
# Execute CLI command with certificate options
459
416
result = cli_runner .invoke (
460
417
cli ,
@@ -478,7 +435,6 @@ def test_serve_certificate_options(cli_runner: CliRunner) -> None:
478
435
479
436
# Ensure logging setup was called with expected arguments
480
437
mock_setup_logging .assert_called_once_with ("INFO" , "JSON" )
481
- mock_logging .assert_called_with ("codegate" )
482
438
483
439
# Verify that run_servers was called with the provided certificate options
484
440
config_arg = mock_run .call_args [0 ][0 ] # Assuming Config is the first positional arg
0 commit comments