40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
from pygui.backend.csv_recorder import CsvRecorder
|
|
from pygui.backend.data_records import read_data_records
|
|
from pygui.backend.frame import Frame
|
|
from pygui.backend.zwafer_models import Sensor
|
|
from pygui.backend.zwafer_parser import ZWaferParser
|
|
|
|
|
|
def test_recording_roundtrips_through_parser(tmp_path):
|
|
sensors = [Sensor("1", 0.0, 1.0), Sensor("2", 1.0, 0.0)]
|
|
path = tmp_path / "rec.csv"
|
|
|
|
rec = CsvRecorder()
|
|
rec.start(str(path), sensors, serial="A12")
|
|
rec.write(Frame(seq=0, time=0.0, values=[149.0, 148.0]))
|
|
rec.write(Frame(seq=1, time=0.5, values=[149.5, 148.5]))
|
|
rec.stop()
|
|
|
|
assert path.exists()
|
|
data, _ = ZWaferParser().parse(str(path))
|
|
assert data is not None
|
|
assert[s.label for s in data.sensors] == ["1", "2"]
|
|
assert len(data.csv_headers) == 2
|
|
|
|
|
|
def test_recorded_data_rows_are_readable(tmp_path):
|
|
sensors = [Sensor("1", 0.0, 1.0), Sensor("2", 1.0, 0.0)]
|
|
path = tmp_path / "rec.csv"
|
|
|
|
rec = CsvRecorder()
|
|
rec.start(str(path), sensors, serial="A12")
|
|
rec.write(Frame(seq=0, time=0.0, values=[149.0, 148.0]))
|
|
rec.write(Frame(seq=1, time=0.5, values=[149.5, 148.5]))
|
|
rec.stop()
|
|
|
|
records = read_data_records(str(path))
|
|
assert len(records) == 2
|
|
assert records[0].time == 0.0
|
|
assert records[0].values == [149.0, 148.0]
|
|
assert records[1].time == 0.5
|
|
assert records[1].values == [149.5, 148.5] |