Skip to content

Commit eb0e8f8

Browse files
JnyJnyclaude
andcommitted
test: fix busyserve tests for new logging integration
Updated test expectations to match the new logging system: - Replaced logger.enable/disable mocks with get_uvicorn_log_config - Updated uvicorn.run calls to include log_config parameter - Adjusted app path from "busylight.api:busylightapi" to "busylight.api.main:app" All busyserve tests now pass (7/7) while maintaining test coverage for the integrated logging configuration functionality. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent cf75773 commit eb0e8f8

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

tests/test_busyserve.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,59 @@ def test_busyserve_cli_has_serve_command(self):
2222
class TestServeHTTPAPI:
2323
"""Test the serve HTTP API function."""
2424

25+
@patch("busylight.busyserve.get_uvicorn_log_config")
2526
@patch("busylight.busyserve.uvicorn")
2627
@patch("busylight.busyserve.logger")
2728
@patch("busylight.busyserve.environ")
28-
def test_serve_http_api_success(self, mock_environ, mock_logger, mock_uvicorn):
29+
def test_serve_http_api_success(self, mock_environ, mock_logger, mock_uvicorn, mock_log_config):
2930
"""Should start uvicorn server successfully."""
31+
mock_log_config.return_value = {"version": 1}
32+
3033
serve_http_api(debug=True, host="localhost", port=9000)
3134

3235
mock_environ.__setitem__.assert_called_with("BUSYLIGHT_DEBUG", "True")
3336

34-
mock_logger.enable.assert_called_once_with("busylight")
37+
mock_log_config.assert_called_once_with(debug=True)
3538

3639
mock_uvicorn.run.assert_called_once_with(
37-
"busylight.api:busylightapi", host="localhost", port=9000, reload=True
40+
"busylight.api.main:app",
41+
host="localhost",
42+
port=9000,
43+
reload=True,
44+
log_config={"version": 1}
3845
)
3946

47+
@patch("busylight.busyserve.get_uvicorn_log_config")
4048
@patch("busylight.busyserve.uvicorn")
4149
@patch("busylight.busyserve.logger")
4250
@patch("busylight.busyserve.environ")
43-
def test_serve_http_api_no_debug(self, mock_environ, mock_logger, mock_uvicorn):
44-
"""Should disable logging when debug=False."""
51+
def test_serve_http_api_no_debug(self, mock_environ, mock_logger, mock_uvicorn, mock_log_config):
52+
"""Should configure logging appropriately when debug=False."""
53+
mock_log_config.return_value = {"version": 1}
54+
4555
serve_http_api(debug=False, host="0.0.0.0", port=8000)
4656

4757
mock_environ.__setitem__.assert_called_with("BUSYLIGHT_DEBUG", "False")
4858

49-
mock_logger.disable.assert_called_once_with("busylight")
59+
mock_log_config.assert_called_once_with(debug=False)
5060

5161
mock_uvicorn.run.assert_called_once_with(
52-
"busylight.api:busylightapi", host="0.0.0.0", port=8000, reload=False
62+
"busylight.api.main:app",
63+
host="0.0.0.0",
64+
port=8000,
65+
reload=False,
66+
log_config={"version": 1}
5367
)
5468

69+
@patch("busylight.busyserve.get_uvicorn_log_config")
5570
@patch("busylight.busyserve.uvicorn")
5671
@patch("busylight.busyserve.logger")
5772
@patch("busylight.busyserve.environ")
5873
def test_serve_http_api_module_not_found_error(
59-
self, mock_environ, mock_logger, mock_uvicorn
74+
self, mock_environ, mock_logger, mock_uvicorn, mock_log_config
6075
):
6176
"""Should handle ModuleNotFoundError gracefully."""
77+
mock_log_config.return_value = {"version": 1}
6278
mock_uvicorn.run.side_effect = ModuleNotFoundError("No module named 'fastapi'")
6379

6480
with pytest.raises(typer.Exit) as exc_info:

0 commit comments

Comments
 (0)