Skip to content

Commit 00dffa6

Browse files
committed
for #78
1 parent 7f05a10 commit 00dffa6

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/test_mbusparser.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
Created on 2025-01-17
3+
4+
@author: wf
5+
"""
6+
import json
7+
from ngwidgets.basetest import Basetest
8+
from ngwidgets.mbus_viewer import MBusParser
9+
10+
class TestMBusParser(Basetest):
11+
"""
12+
test MBusParser
13+
"""
14+
15+
def setUp(self, debug=True, profile=True):
16+
Basetest.setUp(self, debug=debug, profile=profile)
17+
18+
def test_mbus_parser(self):
19+
"""
20+
Test examples from MBusParser class
21+
"""
22+
mbus_parser = MBusParser()
23+
for name, hex_data in mbus_parser.examples.items():
24+
error_msg,json_str = mbus_parser.parse_mbus_data(hex_data)
25+
if self.debug:
26+
marker="✗" if error_msg else "✓"
27+
print(f"{name}{marker}")
28+
if error_msg:
29+
print(error_msg)
30+
else:
31+
json_data=json.loads(json_str)
32+
print(json.dumps(json_data,indent=2))
33+
34+
self.assertIsNone(error_msg, f"Failed to parse {name}")
35+
self.assertIsInstance(json_data, dict)

0 commit comments

Comments
 (0)