diff --git a/hardware-specific-tests/picamera2/test_calibration.py b/hardware-specific-tests/picamera2/test_calibration.py index 9be682a9..622405e7 100644 --- a/hardware-specific-tests/picamera2/test_calibration.py +++ b/hardware-specific-tests/picamera2/test_calibration.py @@ -1,6 +1,7 @@ """Test data collection from the Raspberry Picamera.""" from copy import deepcopy +import tempfile import pytest @@ -10,6 +11,8 @@ from openflexure_microscope_server.things.camera.picamera import ( MissingCalibrationError, ) +from .cam_test_utils import camera_test_client + def test_get_tuning_algo(picamera_thing): """Test that get_tuning algorithm retrieves tuning algorithms.""" @@ -73,3 +76,41 @@ def test_calibration(picamera_thing, picamera_client): # Green equalisation offset should be set to maximum. assert picamera_thing.get_tuning_algo("rpi.geq")["offset"] == 65535 assert picamera_thing.background_detector_status.ready + + +def test_tuning_is_persistent(): + """Check that tuning file adjustments are persistent.""" + # First check full auto-calibrate is persistent if same save dir is used. + with tempfile.TemporaryDirectory() as tmpdir: + with camera_test_client(settings_folder=tmpdir) as client: + initial_tuning = deepcopy(client.tuning) + client.full_auto_calibrate() + calibrated_tuning = deepcopy(client.tuning) + # Full auto calibrate should have saved the tuning. + assert initial_tuning != calibrated_tuning + + # Reload the camera and server from scratch + with camera_test_client(settings_folder=tmpdir) as client: + initial_tuning = deepcopy(client.tuning) + # On reload the initial tuning is as it was when calibrated last run + assert initial_tuning == calibrated_tuning + # Set the lens shading to be flat + client.flat_lens_shading() + flat_tuning = deepcopy(client.tuning) + assert flat_tuning != calibrated_tuning + + # Reload to check the flat lst persists + with camera_test_client(settings_folder=tmpdir) as client: + initial_tuning = deepcopy(client.tuning) + # On reload the initial tuning the flat tuning + assert initial_tuning == flat_tuning + # Reset the lens shading to what is in the default tuning file + client.reset_lens_shading() + flat_tuning = deepcopy(client.tuning) + assert flat_tuning != calibrated_tuning + + # Reload the one more time to check the reset lst persists + with camera_test_client(settings_folder=tmpdir) as client: + initial_tuning = deepcopy(client.tuning) + # On reload the initial tuning the flat tuning + assert initial_tuning == flat_tuning