Add public method docstrings.

This commit is contained in:
Julian Stirling 2025-07-10 15:12:28 +01:00
parent 1bbbfeef0f
commit 14359e73bb
8 changed files with 58 additions and 8 deletions

View file

@ -31,6 +31,7 @@ camera_stage_mapping.DEFAULT_SETTLING_TIME = 0 # skip the settling time for tes
@pytest.fixture
def thing_server():
"""Yield a server with a very basic configuration."""
temp_folder = tempfile.TemporaryDirectory()
server = lt.ThingServer(settings_folder=temp_folder.name)
server.add_thing(
@ -43,36 +44,46 @@ def thing_server():
server.add_thing(AutofocusThing(), "/autofocus/")
server.add_thing(CameraStageMapper(), "/camera_stage_mapping/")
assert os.path.exists(os.path.join(temp_folder.name, "camera/"))
# NB yield is important: otherwise, the temp folder gets deleted before the test runs
# Note: yield is important. If return is used the temp folder gets deleted
# before the test runs
yield server
@pytest.fixture
def client(thing_server):
"""Yield a FastAPI TestClient for the server."""
with TestClient(thing_server.app) as client:
yield client
@pytest.fixture
def slower_client(thing_server):
"""Yield a FastAPI TestClient for the server with a slower moving stage.
The step time for the stage is 100 microseconds rather than
1 microsecond.
"""
thing_server.things["/stage/"].step_time = 0.0001
with TestClient(thing_server.app) as client:
yield client
def test_autofocus(slower_client):
"""Test Fast Autofocus can run doesn't raise an exception."""
client = slower_client
autofocus = lt.ThingClient.from_url("/autofocus/", client)
_ = autofocus.fast_autofocus()
def test_grab_jpeg(client):
"""Check that grab_jpeg returns a blob that can be opened."""
camera = lt.ThingClient.from_url("/camera/", client)
blob = camera.grab_jpeg()
_image = Image.open(blob.open())
def test_capture_jpeg_metadata(client):
"""Check that the position is encoded into the image metadata."""
camera = lt.ThingClient.from_url("/camera/", client)
blob = camera.capture_jpeg()
image = Image.open(blob.open())
@ -83,6 +94,7 @@ def test_capture_jpeg_metadata(client):
def test_stage(client):
"""Test moving th stage forwards and backwards."""
stage = lt.ThingClient.from_url("/stage/", client)
start = stage.position
move = {"x": 1, "y": 2, "z": 3}
@ -97,12 +109,13 @@ def test_stage(client):
def test_capture_array(client):
"""Capture array from simulation and check the size is as expected."""
camera = lt.ThingClient.from_url("/camera/", client)
array = np.asarray(camera.capture_array())
assert array.shape == (240, 320, 3)
# Currently this fails, not yet sure why.
def test_camera_stage_mapping_calibration(client):
"""Check that camera stage mapping can run without an exception."""
camera_stage_mapping = lt.ThingClient.from_url("/camera_stage_mapping/", client)
camera_stage_mapping.calibrate_xy()