Rename "active_detector" for background detecor. Improve thing selector coercion
This commit is contained in:
parent
e46836ffe1
commit
ca46439269
10 changed files with 182 additions and 52 deletions
|
|
@ -19,7 +19,7 @@ def test_calibration(picamera_test_env):
|
|||
# Tuning should start the same as the server is loading with no settings.
|
||||
assert picamera_thing.default_tuning == picamera_thing.tuning
|
||||
# The background detector isn't ready as there is no background image.
|
||||
assert not picamera_thing.active_detector.ready
|
||||
assert not picamera_thing.background_detector.ready
|
||||
|
||||
# Run full auto calibrate
|
||||
picamera_client.full_auto_calibrate()
|
||||
|
|
@ -31,7 +31,7 @@ def test_calibration(picamera_test_env):
|
|||
# The default should be unchanged
|
||||
assert picamera_thing.default_tuning == original_default
|
||||
|
||||
assert picamera_thing.active_detector.ready
|
||||
assert picamera_thing.background_detector.ready
|
||||
|
||||
|
||||
def test_tuning_is_persistent():
|
||||
|
|
|
|||
|
|
@ -186,4 +186,4 @@ def test_simulation_cam_calibration(camera):
|
|||
assert camera.calibration_required
|
||||
camera.full_auto_calibrate()
|
||||
assert not camera.calibration_required
|
||||
assert camera.active_detector.ready
|
||||
assert camera.background_detector.ready
|
||||
|
|
|
|||
59
tests/unit_tests/test_thing_selector.py
Normal file
59
tests/unit_tests/test_thing_selector.py
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
"""Test selector coercion logic for Thing mappings."""
|
||||
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
|
||||
from openflexure_microscope_server.utilities import coerce_thing_selector
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("selected", "default", "warning_count"),
|
||||
[
|
||||
("a", "b", 1),
|
||||
(None, "b", 0),
|
||||
("a", None, 1),
|
||||
(None, None, 0),
|
||||
],
|
||||
)
|
||||
def test_coerce_with_empty_mapping(selected, default, warning_count, caplog):
|
||||
"""Test None always returned for empty mappings, check warnings when appropriate."""
|
||||
with caplog.at_level(logging.WARNING):
|
||||
output = coerce_thing_selector(
|
||||
thing_mapping={}, selected=selected, default=default
|
||||
)
|
||||
assert output is None
|
||||
assert len(caplog.records) == warning_count
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("selected", "default", "returned", "warning_count"),
|
||||
[
|
||||
("b", "b", "b", 0),
|
||||
("b", "a", "b", 0),
|
||||
("b", None, "b", 0),
|
||||
("b", "z", "b", 0),
|
||||
(None, "b", "b", 0),
|
||||
(None, "a", "a", 0),
|
||||
(None, None, "a", 0),
|
||||
(None, "z", "a", 1),
|
||||
("z", "b", "b", 1),
|
||||
("z", "a", "a", 1),
|
||||
("z", None, "a", 1),
|
||||
("z", "z", "a", 2),
|
||||
],
|
||||
)
|
||||
def test_coerce_with_populated_mapping(
|
||||
selected, default, returned, warning_count, caplog
|
||||
):
|
||||
"""Test coercion of selected key for a populated thing mapping.
|
||||
|
||||
Check that warnings are raised when appropriate.
|
||||
"""
|
||||
thing_mapping = {"a": "Foo", "b": "Bar", "c": "FooBar"}
|
||||
with caplog.at_level(logging.WARNING):
|
||||
output = coerce_thing_selector(
|
||||
thing_mapping=thing_mapping, selected=selected, default=default
|
||||
)
|
||||
assert output == returned
|
||||
assert len(caplog.records) == warning_count
|
||||
Loading…
Add table
Add a link
Reference in a new issue