Update customise_server to poll the debug flag in the LT server instead of re-reading the value from CLI arguments.
This commit is contained in:
parent
d3c4773884
commit
b235de39f6
2 changed files with 15 additions and 9 deletions
|
|
@ -72,7 +72,7 @@ def set_shutdown_function(shutdown_function: Callable[[], None]) -> None:
|
|||
|
||||
|
||||
def customise_server(
|
||||
server: lt.ThingServer, application_config: OFMApplicationData, debug: bool = False
|
||||
server: lt.ThingServer, application_config: OFMApplicationData
|
||||
) -> None:
|
||||
"""Customise the server with additional endpoints, debug mode etc."""
|
||||
if DEVELOPER_MODE:
|
||||
|
|
@ -88,8 +88,9 @@ def customise_server(
|
|||
add_v2_endpoints(server)
|
||||
add_static_files(server, application_config.data_folder)
|
||||
|
||||
# Configure logging to DEBUG if requested in CLI args.
|
||||
if debug:
|
||||
# Configure logging to DEBUG if LT server is set up
|
||||
# with debug = true
|
||||
if server.debug:
|
||||
lt.logs.configure_thing_logger(logging.DEBUG)
|
||||
|
||||
# Add an endpoint to get the logs - (directly calling the FastAPI decorator)
|
||||
|
|
@ -119,9 +120,8 @@ def serve_from_cli(argv: Optional[list[str]] = None) -> None:
|
|||
application_config = OFMApplicationData(**lt_config.application_config)
|
||||
configure_logging(application_config.log_folder)
|
||||
|
||||
server = lt.ThingServer.from_config(lt_config)
|
||||
debug = bool(args.debug)
|
||||
customise_server(server, application_config, debug)
|
||||
server = lt.ThingServer.from_config(lt_config, args.debug)
|
||||
customise_server(server, application_config)
|
||||
|
||||
def shutdown_call() -> None:
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -109,14 +109,20 @@ def test_failed_customise(mocker):
|
|||
# An that it has the error to display
|
||||
assert str(fallback_app._context.error) == "Can't touch this"
|
||||
|
||||
|
||||
def test_debug_mode(mocker):
|
||||
"""Test that --debug flag triggers lt.logs.configure_thing_logger."""
|
||||
# Mock the LabThings function that returns the server
|
||||
|
||||
# Use a side_effect to map the CLI debug arg to the mock server's debug attribute
|
||||
def mock_from_config(_, debug_flag):
|
||||
mock_server = mocker.Mock()
|
||||
mock_server.debug = debug_flag # This will now be correctly True or False
|
||||
return mock_server
|
||||
|
||||
mocker.patch(
|
||||
"openflexure_microscope_server.server.lt.ThingServer.from_config",
|
||||
return_value=mocker.Mock(),
|
||||
side_effect=mock_from_config,
|
||||
)
|
||||
|
||||
# Mock customisation dependencies to avoid side effects
|
||||
mocker.patch.object(ofm_server, "add_v2_endpoints")
|
||||
mocker.patch.object(ofm_server, "add_static_files")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue