Update tests for new camera streaming modes

This commit is contained in:
Julian Stirling 2026-05-26 22:28:51 +01:00
parent aff860a086
commit 7dd715da88
8 changed files with 27 additions and 35 deletions

View file

@ -5,7 +5,7 @@ from contextlib import contextmanager
from typing import Optional
from openflexure_microscope_server.things.background_detect import ChannelDeviationLUV
from openflexure_microscope_server.things.camera.picamera import StreamingPiCamera2
from openflexure_microscope_server.things.camera.picamera import PiCameraV2
from ...shared_utils.lt_test_utils import LabThingsTestEnv
@ -21,7 +21,7 @@ def camera_test_env(settings_folder: Optional[str] = None):
temporary directory will be used as the settings folder.
"""
thing_conf = {
"camera": StreamingPiCamera2,
"camera": PiCameraV2,
"bg_channel_deviations_luv": ChannelDeviationLUV,
}
app_config = {

View file

@ -9,7 +9,7 @@ from .cam_test_utils import camera_test_env
@pytest.fixture
def picamera_test_env() -> lt.ThingClient:
"""Initialise a test environment with only a StreamingPiCamera2 Thing."""
"""Initialise a test environment with only a PiCameraV2 Thing."""
with camera_test_env() as env:
yield env

View file

@ -93,13 +93,13 @@ def test_exposure_time_on_start_and_stop_stream():
print(f"Starting simulation scan {i}")
# This will need updating if we start supporting other Picamera models
# It is currently used here to mimic the behaviour in in scanning.
client.start_streaming(main_resolution=(3280, 2464))
client.change_streaming_mode(mode="full_resolution")
time.sleep(0.5)
for _j in range(5):
client.capture_to_memory(buffer_max=1)
# Reset to main resolution
time.sleep(0.5)
client.start_streaming()
client.change_streaming_mode(mode="default")
# Check after all of this the exposure time is the same.
assert client.exposure_time == set_time

View file

@ -9,13 +9,13 @@ from .cam_test_utils import camera_test_client
logging.basicConfig(level=logging.DEBUG)
def test_sensor_mode():
def test_streaming_mode():
"""Test capturing raw arrays in two different sensor modes."""
with camera_test_client() as client:
for size in [(3280, 2464), (1640, 1232)]:
client.sensor_mode = {"output_size": size, "bit_depth": 10}
arr = np.array(client.capture_array(stream_name="raw"))
for mode, res in ["default", (820, 616)], ["full_resolution", (3280, 2464)]:
client.change_streaming_mode(mode=mode)
arr = np.array(client.capture_array(stream_name="main"))
# Check that the array dimensions match the requested image size.
# Note: Numpy array shape is (y,x), but the sensor is set with (x,y)
# hence the need to compare index 0 with index 1.
assert arr.shape[0] == size[1]
assert arr.shape[0] == res[1]