Testing a Viewer
A plot is an ordinary function or object: it takes the run’s data and returns
drawables (see Plots and Drawables). So it can be tested without a
window, a screen or the gui extra, by giving it the data of a stored run and
checking what it returns.
# tests/test_viz.py
from plesty.lib.monitor import Line, RunData
from power_viz import power # the plot function of the viewer being tested
def test_power_draws_one_point_per_step():
data = RunData("tests/runs/powerscan_20260925-101534")
data.poll() # read the rows saved so far
drawing = power(data)
assert len(drawing) == 1
assert isinstance(drawing[0], Line)
assert list(drawing[0].x) == [500.0, 550.0, 600.0, 650.0, 700.0]
RunData(run_folder)reads nothing yet;poll()reads every row saved so far and returns how many it read. In a viewer,Vizdoes this at each refresh.@viz.plotreturns the function unchanged, so the test callspower(data)directly. For aPlotobject, callplot.draw(data).Keep a small finished run in the module’s tests, made by running the experiment once on its simulated devices, so the test does not depend on a lab computer.
A viewer’s reads= function can be tested the same way: call it with a row and a
Run, and check the fields it returns.