|
4 | 4 | import pytest |
5 | 5 | from pytest import mark |
6 | 6 |
|
7 | | -from harp.io import MessageType, read |
| 7 | +from harp.io import MessageType, parse, read |
8 | 8 | from tests.params import DataFileParam |
9 | 9 |
|
10 | 10 | testdata = [ |
|
29 | 29 | ), |
30 | 30 | DataFileParam(path="data/write_0.bin", expected_address=0, expected_rows=4), |
31 | 31 | 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), |
32 | 33 | ] |
33 | 34 |
|
34 | 35 |
|
35 | 36 | @mark.parametrize("dataFile", testdata) |
36 | 37 | def test_read(dataFile: DataFileParam): |
37 | 38 | context = pytest.raises if dataFile.expected_error else nullcontext |
38 | 39 | 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 | + ) |
46 | 59 | assert len(data) == dataFile.expected_rows |
47 | 60 | if dataFile.keep_type: |
48 | 61 | assert MessageType.__name__ in data.columns and data[MessageType.__name__].dtype == "category" |
|
0 commit comments