|
4 | 4 | import pytest |
5 | 5 | from pytest import mark |
6 | 6 |
|
7 | | -from harp.io import MessageType, parse, read |
| 7 | +from harp.io import MessageType, format, parse, read |
8 | 8 | from tests.params import DataFileParam |
9 | 9 |
|
10 | 10 | testdata = [ |
@@ -63,3 +63,26 @@ def test_read(dataFile: DataFileParam): |
63 | 63 | if dataFile.expected_cols: |
64 | 64 | for col in dataFile.expected_cols: |
65 | 65 | 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