Skip to content

Commit 0320814

Browse files
committed
Add test for parsing data from long buffer
1 parent 645bd5e commit 0320814

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

tests/params.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class DataFileParam:
1919
expected_dtype: Optional[np.dtype] = None
2020
expected_length: Optional[int] = None
2121
expected_error: Optional[Type[BaseException]] = None
22+
repeat_data: Optional[int] = None
2223
keep_type: bool = False
2324

2425
def __post_init__(self):

tests/test_io.py

Lines changed: 21 additions & 8 deletions
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, read
7+
from harp.io import MessageType, parse, read
88
from tests.params import DataFileParam
99

1010
testdata = [
@@ -29,20 +29,33 @@
2929
),
3030
DataFileParam(path="data/write_0.bin", expected_address=0, expected_rows=4),
3131
DataFileParam(path="data/write_0.bin", expected_address=0, expected_rows=4, keep_type=True),
32+
DataFileParam(path="data/device_0.bin", expected_rows=300, repeat_data=300),
3233
]
3334

3435

3536
@mark.parametrize("dataFile", testdata)
3637
def test_read(dataFile: DataFileParam):
3738
context = pytest.raises if dataFile.expected_error else nullcontext
3839
with context(dataFile.expected_error): # type: ignore
39-
data = read(
40-
dataFile.path,
41-
address=dataFile.expected_address,
42-
dtype=dataFile.expected_dtype,
43-
length=dataFile.expected_length,
44-
keep_type=dataFile.keep_type,
45-
)
40+
path = dataFile.path
41+
if dataFile.repeat_data:
42+
with open(path, "rb") as f:
43+
buffer = f.read() * dataFile.repeat_data
44+
data = parse(
45+
buffer,
46+
address=dataFile.expected_address,
47+
dtype=dataFile.expected_dtype,
48+
length=dataFile.expected_length,
49+
keep_type=dataFile.keep_type,
50+
)
51+
else:
52+
data = read(
53+
path,
54+
address=dataFile.expected_address,
55+
dtype=dataFile.expected_dtype,
56+
length=dataFile.expected_length,
57+
keep_type=dataFile.keep_type,
58+
)
4659
assert len(data) == dataFile.expected_rows
4760
if dataFile.keep_type:
4861
assert MessageType.__name__ in data.columns and data[MessageType.__name__].dtype == "category"

0 commit comments

Comments
 (0)