Update tests for stage without deps

This commit is contained in:
Julian Stirling 2025-12-16 14:05:18 +00:00
parent 426178ba31
commit 3332bc5e1d
2 changed files with 4 additions and 41 deletions

View file

@ -1,19 +0,0 @@
"""Create a fake CancelHook used instead of a dependency, it cannot be used to cancel!
Certain actions require a CancelHook to be supplied if called directly. The only method
we use from the LabThings CancelHook is ``sleep()``. The CanceHook ``sleep()`` works
exactly like ``time.sleep()`` except with raise an ``InvocationCancelledError`` if the
server receives a cancellation request.
This is just an object with a sleep method.
"""
import time
class MockCancel:
"""A class to use when directly calling an action with CancelHook dependency."""
def sleep(self, time_in_seconds: float) -> None:
"""Sleep for the input number of seconds."""
time.sleep(time_in_seconds)

View file

@ -18,8 +18,6 @@ from openflexure_microscope_server.things.stage import (
) )
from openflexure_microscope_server.things.stage.dummy import DummyStage from openflexure_microscope_server.things.stage.dummy import DummyStage
from .mock_things.mock_cancel import MockCancel
# Keep the size and number of moves fairly small or the tests can take forever # Keep the size and number of moves fairly small or the tests can take forever
point3d = st.tuples( point3d = st.tuples(
st.integers(min_value=-100, max_value=100), st.integers(min_value=-100, max_value=100),
@ -60,12 +58,7 @@ def test_override_base_movement():
class BadStage1(BaseStage): class BadStage1(BaseStage):
@lt.action @lt.action
def move_relative( def move_relative(self, block_cancellation: bool = False, **kwargs: int):
self,
cancel: lt.deps.CancelHook,
block_cancellation: bool = False,
**kwargs: int,
):
pass pass
with pytest.raises(RedefinedBaseMovementError): with pytest.raises(RedefinedBaseMovementError):
@ -73,12 +66,7 @@ def test_override_base_movement():
class BadStage2(BaseStage): class BadStage2(BaseStage):
@lt.action @lt.action
def move_absolute( def move_absolute(self, block_cancellation: bool = False, **kwargs: int):
self,
cancel: lt.deps.CancelHook,
block_cancellation: bool = False,
**kwargs: int,
):
pass pass
with pytest.raises(RedefinedBaseMovementError): with pytest.raises(RedefinedBaseMovementError):
@ -200,7 +188,6 @@ def _test_move_relative(dummy_stage, axis_inverted, path):
:param axis_inverted: Is used to set the inversion. :param axis_inverted: Is used to set the inversion.
:param path: The 3d path to move over, generated by hypothesis. :param path: The 3d path to move over, generated by hypothesis.
""" """
cancel = MockCancel()
dummy_stage.axis_inverted = axis_inverted dummy_stage.axis_inverted = axis_inverted
# Explicitly do axes calculation here to check logic in main code. # Explicitly do axes calculation here to check logic in main code.
x_dir = -1 if axis_inverted["x"] else 1 x_dir = -1 if axis_inverted["x"] else 1
@ -209,9 +196,7 @@ def _test_move_relative(dummy_stage, axis_inverted, path):
position = list(dummy_stage.position.values()) position = list(dummy_stage.position.values())
for movement in path: for movement in path:
dummy_stage.move_relative( dummy_stage.move_relative(x=movement[0], y=movement[1], z=movement[2])
cancel=cancel, x=movement[0], y=movement[1], z=movement[2]
)
position = [pos + move for pos, move in zip(position, movement, strict=True)] position = [pos + move for pos, move in zip(position, movement, strict=True)]
stage_pos = dummy_stage.get_xyz_position() stage_pos = dummy_stage.get_xyz_position()
hw_pos = dummy_stage._hardware_position hw_pos = dummy_stage._hardware_position
@ -257,7 +242,6 @@ def _test_move_absolute(dummy_stage, axis_inverted, path):
:param axis_inverted: Is used to set the inversion. :param axis_inverted: Is used to set the inversion.
:param path: The 3d path to move over, generated by hypothesis. :param path: The 3d path to move over, generated by hypothesis.
""" """
cancel = MockCancel()
dummy_stage.axis_inverted = axis_inverted dummy_stage.axis_inverted = axis_inverted
# Explicitly do axes calculation here to check logic in main code. # Explicitly do axes calculation here to check logic in main code.
x_dir = -1 if axis_inverted["x"] else 1 x_dir = -1 if axis_inverted["x"] else 1
@ -265,9 +249,7 @@ def _test_move_absolute(dummy_stage, axis_inverted, path):
z_dir = -1 if axis_inverted["z"] else 1 z_dir = -1 if axis_inverted["z"] else 1
position = list(dummy_stage.position.values()) position = list(dummy_stage.position.values())
for move_to in path: for move_to in path:
dummy_stage.move_absolute( dummy_stage.move_absolute(x=move_to[0], y=move_to[1], z=move_to[2])
cancel=cancel, x=move_to[0], y=move_to[1], z=move_to[2]
)
position = move_to position = move_to
stage_pos = dummy_stage.get_xyz_position() stage_pos = dummy_stage.get_xyz_position()
hw_pos = dummy_stage._hardware_position hw_pos = dummy_stage._hardware_position