Testing a Device
DevicePipeline, in plesty.lib.test.device_pipeline, is the standard test of a
device module. It needs no instrument: it replaces the instrument with a simulated one
that answers every parameter and operation with a made-up value of the declared type,
and checks the device against it. It therefore runs anywhere, including in CI on
every push.
The test file
A device module’s whole test file is:
# tests/test_mydevice.py
from plesty.lib.test.device_pipeline import DevicePipeline
from plesty.mydevice import Device
PIPELINE = DevicePipeline(Device, address="mock")
def test_mock_pipeline():
PIPELINE.run_mock_pipeline()
Arguments after the class are passed to its constructor. plesty init mock-test,
a command of plesty-sdk, PLESTY’s developer tool, writes this file for a module from
what the module declares.
run_mock_pipeline() runs all eight tests below and reports every failure it finds,
rather than stopping at the first. plesty-sdk looks for this test and runs it as gate
d1 of plesty check before the module may be published (see
Which tests each module runs).
What it checks
Test |
Checks |
|---|---|
|
what the device declares ( |
|
every key in |
|
every parameter can be read and written against the simulated instrument |
|
every operation accepts generated arguments |
|
a |
|
|
|
|
|
|
The tests read the device itself, never its schema files. A parameter registered in Python code does not appear in the JSON file, and in a grouped schema the file’s keys are not the keys the running device answers to, so only the device is a reliable source.
What passing does not mean
These tests show that a module’s declarations are consistent and that its parameter and operation handling works. They cannot show that the instrument accepts the commands the module sends, that its driver is installed, or how the connection behaves when it goes wrong: a simulated instrument has none of these. A module that passes all eight can still fail on the instrument. That is what Testing on the Instrument is for.