Skip to content

Commit 895c74d

Browse files
committed
Add round-trip regression tests for binary format
1 parent a331cea commit 895c74d

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

tests/test_io.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55
from pytest import mark
66

7-
from harp.io import MessageType, parse, read
7+
from harp.io import MessageType, format, parse, read
88
from tests.params import DataFileParam
99

1010
testdata = [
@@ -63,3 +63,26 @@ def test_read(dataFile: DataFileParam):
6363
if dataFile.expected_cols:
6464
for col in dataFile.expected_cols:
6565
assert col in data.columns
66+
67+
68+
writedata = [
69+
DataFileParam(path="data/device_0.bin", expected_rows=1, expected_address=0, keep_type=True),
70+
]
71+
72+
73+
@mark.parametrize("dataFile", writedata)
74+
def test_write(dataFile: DataFileParam):
75+
if dataFile.expected_address is None:
76+
raise AssertionError("expected address must be defined for all write tests")
77+
78+
buffer = np.fromfile(dataFile.path, np.uint8)
79+
data = parse(
80+
buffer,
81+
address=dataFile.expected_address,
82+
dtype=dataFile.expected_dtype,
83+
length=dataFile.expected_length,
84+
keep_type=dataFile.keep_type,
85+
)
86+
assert len(data) == dataFile.expected_rows
87+
write_buffer = format(data, address=dataFile.expected_address)
88+
assert np.array_equal(buffer, write_buffer)

0 commit comments

Comments
 (0)