Skip to content

Commit cb9856d

Browse files
committed
tests: tdf: add simple parsing check
Add a basic check that parsing works as expected. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent 6f3279a commit cb9856d

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

tests/tdf/tdf_example.bin

5 KB
Binary file not shown.

tests/tdf/test_tdf.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import os
2+
3+
from infuse_iot.tdf import TDF
4+
5+
# assert "TOXTEMPDIR" in os.environ, "you must run these tests using tox"
6+
7+
TESTDATA_FILENAME = os.path.join(os.path.dirname(__file__), "tdf_example.bin")
8+
9+
10+
def test_tdf():
11+
with open(TESTDATA_FILENAME, "rb") as f:
12+
test_data = f.read(-1)
13+
14+
test_blocks = [test_data[i : (i + 512)] for i in range(0, len(test_data), 512)]
15+
16+
decoder = TDF()
17+
total_tdfs = 0
18+
19+
# Iterate over each block
20+
for block in test_blocks:
21+
assert len(block) % 512 == 0
22+
# Iterate over each TDF in the block
23+
for tdf in decoder.decode(block):
24+
assert isinstance(tdf, TDF.Reading)
25+
total_tdfs += 1
26+
27+
# Number of TDFs on the example block should never change
28+
assert total_tdfs == 53

0 commit comments

Comments
 (0)