From dfe50f5c569ffe963efbc45381598f244b510f4d Mon Sep 17 00:00:00 2001 From: Julian Stirling Date: Sun, 11 Jan 2026 12:14:44 +0000 Subject: [PATCH] Split up generic camera tests and simulation specific ones. --- .../{test_camera.py => test_base_camera.py} | 16 +++++------ tests/unit_tests/test_simulated_camera.py | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+), 10 deletions(-) rename tests/unit_tests/{test_camera.py => test_base_camera.py} (82%) create mode 100644 tests/unit_tests/test_simulated_camera.py diff --git a/tests/unit_tests/test_camera.py b/tests/unit_tests/test_base_camera.py similarity index 82% rename from tests/unit_tests/test_camera.py rename to tests/unit_tests/test_base_camera.py index 6f49b6f3..e6945826 100644 --- a/tests/unit_tests/test_camera.py +++ b/tests/unit_tests/test_base_camera.py @@ -1,4 +1,9 @@ -"""Use the Simulation camera to test base camera functionality.""" +"""Use the Simulated camera to test base camera functionality. + +For tests of functionality specific to the simulated camera see +test_simulated_camera.py and for testing the consistency of camera APIs see +test_cameras.py. +""" import numpy as np import pytest @@ -58,12 +63,3 @@ def test_handle_broken_frame(test_env): for _i in range(15): array = camera.grab_as_array() assert isinstance(array, np.ndarray) - - -def test_simulation_cam_calibration(test_env): - """Test that the simulated camera can be calibrated and reports calibration correctly.""" - camera = test_env.get_thing_by_type(SimulatedCamera) - assert camera.calibration_required - camera.full_auto_calibrate() - assert not camera.calibration_required - assert camera.background_detector_status.ready diff --git a/tests/unit_tests/test_simulated_camera.py b/tests/unit_tests/test_simulated_camera.py new file mode 100644 index 00000000..0e7442ea --- /dev/null +++ b/tests/unit_tests/test_simulated_camera.py @@ -0,0 +1,27 @@ +"""Test the functionality specific to the simulated camera.""" + +import pytest + +import labthings_fastapi as lt + +from openflexure_microscope_server.things.camera.simulation import SimulatedCamera +from openflexure_microscope_server.things.stage.dummy import DummyStage + +from ..shared_utils.lt_test_utils import LabThingsTestEnv + + +@pytest.fixture +def test_env() -> lt.ThingClient: + """Yield a test environment with the Simulated Camera and Dummy Stage.""" + thing_conf = {"camera": SimulatedCamera, "stage": DummyStage} + with LabThingsTestEnv(things=thing_conf) as env: + yield env + + +def test_simulation_cam_calibration(test_env): + """Test that the simulated camera can be calibrated and reports calibration correctly.""" + camera = test_env.get_thing_by_type(SimulatedCamera) + assert camera.calibration_required + camera.full_auto_calibrate() + assert not camera.calibration_required + assert camera.background_detector_status.ready