Make picamera tests compatible with updates
This commit is contained in:
parent
13d3871059
commit
c0362ee8dd
1 changed files with 1 additions and 49 deletions
|
|
@ -3,48 +3,9 @@
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
import labthings_fastapi as lt
|
|
||||||
|
|
||||||
from openflexure_microscope_server.things.camera.picamera import (
|
|
||||||
MissingCalibrationError,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .cam_test_utils import camera_test_client
|
from .cam_test_utils import camera_test_client
|
||||||
|
|
||||||
|
|
||||||
def test_get_tuning_algo(picamera_thing):
|
|
||||||
"""Test that get_tuning algorithm retrieves tuning algorithms."""
|
|
||||||
# Missing algorithm raises an error.
|
|
||||||
with pytest.raises(MissingCalibrationError):
|
|
||||||
picamera_thing.get_tuning_algo("foo")
|
|
||||||
# Or returns None if explicitly told not to error.
|
|
||||||
assert picamera_thing.get_tuning_algo("foo", raise_if_missing=False) is None
|
|
||||||
|
|
||||||
# Real algorithm is a dict and contains expected keys
|
|
||||||
assert isinstance(picamera_thing.get_tuning_algo("rpi.geq"), dict)
|
|
||||||
assert "offset" in picamera_thing.get_tuning_algo("rpi.geq")
|
|
||||||
|
|
||||||
# Set the tuning to None as it is technically optional. And check this
|
|
||||||
# is handled gracefully. This needs to be done in a try block as LabThings
|
|
||||||
# tries and fails to emit an event.
|
|
||||||
try:
|
|
||||||
picamera_thing.tuning = None
|
|
||||||
except lt.exceptions.NotConnectedToServerError:
|
|
||||||
# Labthings will complain that it is not connected to a server
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Check it is set to None despite the above LabThings issue.
|
|
||||||
assert picamera_thing.tuning is None
|
|
||||||
|
|
||||||
# Raises an error as there is no tuning file set.
|
|
||||||
with pytest.raises(MissingCalibrationError):
|
|
||||||
picamera_thing.get_tuning_algo("rpi.geq")
|
|
||||||
# Or returns None if explicitly told not to error.
|
|
||||||
assert picamera_thing.get_tuning_algo("rpi.geq", raise_if_missing=False) is None
|
|
||||||
|
|
||||||
|
|
||||||
def test_calibration(picamera_thing, picamera_client):
|
def test_calibration(picamera_thing, picamera_client):
|
||||||
"""Check that full auto calibrate completes and set the expected values."""
|
"""Check that full auto calibrate completes and set the expected values."""
|
||||||
# Check the calibration_required property used by the calibration wizard
|
# Check the calibration_required property used by the calibration wizard
|
||||||
|
|
@ -53,9 +14,6 @@ def test_calibration(picamera_thing, picamera_client):
|
||||||
original_default = deepcopy(picamera_thing.default_tuning)
|
original_default = deepcopy(picamera_thing.default_tuning)
|
||||||
# Tuning should start the same as the server is loading with no settings.
|
# Tuning should start the same as the server is loading with no settings.
|
||||||
assert picamera_thing.default_tuning == picamera_thing.tuning
|
assert picamera_thing.default_tuning == picamera_thing.tuning
|
||||||
# lens_shading tables should be None when loaded on default tuning as it is
|
|
||||||
# adaptive
|
|
||||||
assert picamera_thing.lens_shading_tables is None
|
|
||||||
# The background detector isn't ready as there is no background image.
|
# The background detector isn't ready as there is no background image.
|
||||||
assert not picamera_thing.background_detector_status.ready
|
assert not picamera_thing.background_detector_status.ready
|
||||||
|
|
||||||
|
|
@ -68,13 +26,7 @@ def test_calibration(picamera_thing, picamera_client):
|
||||||
assert picamera_thing.default_tuning != picamera_thing.tuning
|
assert picamera_thing.default_tuning != picamera_thing.tuning
|
||||||
# The default should be unchanged
|
# The default should be unchanged
|
||||||
assert picamera_thing.default_tuning == original_default
|
assert picamera_thing.default_tuning == original_default
|
||||||
# Lens shading tables should no longer be None
|
|
||||||
assert picamera_thing.lens_shading_tables is not None
|
|
||||||
# There should be exactly one colour correction matrix
|
|
||||||
# (no variations by colour temp)
|
|
||||||
assert len(picamera_thing.get_tuning_algo("rpi.ccm")["ccms"]) == 1
|
|
||||||
# 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
|
assert picamera_thing.background_detector_status.ready
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue