openflexure-microscope-server/tests/mock_things/mock_cancel.py
Julian Stirling 3a4b99df55 Apply suggestions from code review of branch faster-stage-tests
Co-authored-by: Beth Probert <beth_probert@outlook.com>
2025-08-08 09:32:31 +00:00

19 lines
698 B
Python

"""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)