Split calibration and aquisition tests
This commit is contained in:
parent
ab0bece70b
commit
c209d524c5
2 changed files with 53 additions and 28 deletions
|
|
@ -1,7 +1,5 @@
|
||||||
"""Test data collection from the Raspberry Picamera."""
|
"""Test data collection from the Raspberry Picamera."""
|
||||||
|
|
||||||
import tempfile
|
|
||||||
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
@ -12,18 +10,8 @@ import labthings_fastapi as lt
|
||||||
from openflexure_microscope_server.things.camera.picamera import StreamingPiCamera2
|
from openflexure_microscope_server.things.camera.picamera import StreamingPiCamera2
|
||||||
|
|
||||||
|
|
||||||
@fixture()
|
@fixture(scope="module")
|
||||||
def picamera_thing() -> StreamingPiCamera2:
|
def client() -> lt.ThingClient:
|
||||||
"""Return a StreamingPiCamera2 Thing.
|
|
||||||
|
|
||||||
This is the Thing that the fixture client uses. It can be used to probe the
|
|
||||||
Thing directly to check actions had the expected response.
|
|
||||||
"""
|
|
||||||
return StreamingPiCamera2()
|
|
||||||
|
|
||||||
|
|
||||||
@fixture()
|
|
||||||
def client(picamera_thing) -> lt.ThingClient:
|
|
||||||
"""Initialise a test client for the StreamingPiCamera2 Thing.
|
"""Initialise a test client for the StreamingPiCamera2 Thing.
|
||||||
|
|
||||||
This fixture:
|
This fixture:
|
||||||
|
|
@ -32,25 +20,13 @@ def client(picamera_thing) -> lt.ThingClient:
|
||||||
* Registers a StreamingPiCamera2 instance at the "/camera/" endpoint
|
* Registers a StreamingPiCamera2 instance at the "/camera/" endpoint
|
||||||
* Provides a ThingClient for interacting with it during tests.
|
* Provides a ThingClient for interacting with it during tests.
|
||||||
"""
|
"""
|
||||||
temp_folder = tempfile.TemporaryDirectory()
|
server = lt.ThingServer()
|
||||||
server = lt.ThingServer(settings_folder=temp_folder.name)
|
server.add_thing(StreamingPiCamera2(), "/camera/")
|
||||||
server.add_thing(picamera_thing, "/camera/")
|
|
||||||
with TestClient(server.app) as test_client:
|
with TestClient(server.app) as test_client:
|
||||||
client = lt.ThingClient.from_url("/camera/", client=test_client)
|
client = lt.ThingClient.from_url("/camera/", client=test_client)
|
||||||
yield client
|
yield client
|
||||||
|
|
||||||
|
|
||||||
def test_calibration(picamera_thing, client):
|
|
||||||
"""Check that full auto calibrate completes without an exception."""
|
|
||||||
tuning = picamera_thing.tuning
|
|
||||||
default_tuning = picamera_thing.default_tuning
|
|
||||||
# Tuning should start the same as the server is loading with no settings.
|
|
||||||
assert default_tuning == tuning
|
|
||||||
# After calibration they should be different
|
|
||||||
client.full_auto_calibrate()
|
|
||||||
assert default_tuning != tuning
|
|
||||||
|
|
||||||
|
|
||||||
def test_jpeg_and_array(client):
|
def test_jpeg_and_array(client):
|
||||||
"""Check that a jpeg grabbed from the stream is the same size as other captures.
|
"""Check that a jpeg grabbed from the stream is the same size as other captures.
|
||||||
|
|
||||||
|
|
|
||||||
49
hardware-specific-tests/picamera2/test_calibration.py
Normal file
49
hardware-specific-tests/picamera2/test_calibration.py
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
"""Test data collection from the Raspberry Picamera."""
|
||||||
|
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
from fastapi.testclient import TestClient
|
||||||
|
from pytest import fixture
|
||||||
|
|
||||||
|
import labthings_fastapi as lt
|
||||||
|
|
||||||
|
from openflexure_microscope_server.things.camera.picamera import StreamingPiCamera2
|
||||||
|
|
||||||
|
|
||||||
|
@fixture()
|
||||||
|
def picamera_thing() -> StreamingPiCamera2:
|
||||||
|
"""Return a StreamingPiCamera2 Thing.
|
||||||
|
|
||||||
|
This is the Thing that the fixture client uses. It can be used to probe the
|
||||||
|
Thing directly to check actions had the expected response.
|
||||||
|
"""
|
||||||
|
return StreamingPiCamera2()
|
||||||
|
|
||||||
|
|
||||||
|
@fixture()
|
||||||
|
def client(picamera_thing) -> lt.ThingClient:
|
||||||
|
"""Initialise a test client for the StreamingPiCamera2 Thing.
|
||||||
|
|
||||||
|
This fixture:
|
||||||
|
|
||||||
|
* Sets up a ThingServer,
|
||||||
|
* Registers a StreamingPiCamera2 instance at the "/camera/" endpoint
|
||||||
|
* Provides a ThingClient for interacting with it during tests.
|
||||||
|
"""
|
||||||
|
temp_folder = tempfile.TemporaryDirectory()
|
||||||
|
server = lt.ThingServer(settings_folder=temp_folder.name)
|
||||||
|
server.add_thing(picamera_thing, "/camera/")
|
||||||
|
with TestClient(server.app) as test_client:
|
||||||
|
client = lt.ThingClient.from_url("/camera/", client=test_client)
|
||||||
|
yield client
|
||||||
|
|
||||||
|
|
||||||
|
def test_calibration(picamera_thing, client):
|
||||||
|
"""Check that full auto calibrate completes without an exception."""
|
||||||
|
tuning = picamera_thing.tuning
|
||||||
|
default_tuning = picamera_thing.default_tuning
|
||||||
|
# Tuning should start the same as the server is loading with no settings.
|
||||||
|
assert default_tuning == tuning
|
||||||
|
# After calibration they should be different
|
||||||
|
client.full_auto_calibrate()
|
||||||
|
assert default_tuning != tuning
|
||||||
Loading…
Add table
Add a link
Reference in a new issue