forked from sampottinger/ljsimpleregisterlookup
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserialize_test.py
More file actions
101 lines (92 loc) · 2.54 KB
/
serialize_test.py
File metadata and controls
101 lines (92 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
"""Tests for serializing modbus information for Simple Register Lookup.
@author Sam Pottinger
@license GNU GPL v2
"""
import unittest
import serialize
# TODO: This is still somewhat incomplete
class SerializeTests(unittest.TestCase):
"""Test case for reading LabJack Modbus Map Markup notation maps."""
def test_serialize_device_modbus_map(self):
"""Test serializing a modbus map for a single device."""
test_modbus_map = [
{
"name": "test_1",
"address": 1,
"type": "UINT16",
"numregs": 1,
"fwmin": 0,
"readwrite": {
"read": True,
"write": False
},
"tags": ["tag1", "tag2"],
"description": "test1"
},
{
"name": "test_2",
"address": 2,
"type": "UINT16",
"numregs": 1,
"fwmin": 0,
"readwrite": {
"read": False,
"write": True
},
"tags": ["tag3", "tag4"],
"description": "test2",
"altnames": ["alternate_name"],
"usesRAM": True,
}
]
expected = [
[
"name",
"address",
"type",
"access",
"tags",
"description",
"default",
"streamable",
"isBuffer",
"devices",
"constants",
"altnames",
"usesRAM",
],
[
"test_1",
1,
"UINT16",
"R",
"tag1, tag2",
"test1",
"",
None,
None,
None,
None,
[],
None,
],
[
"test_2 (also known as: alternate_name)",
2,
"UINT16",
"W",
"tag3, tag4",
"test2",
"",
None,
None,
None,
None,
['alternate_name'],
True,
]
]
serialized = serialize.serialize_device_modbus_map(test_modbus_map)
self.assertListEqual(serialized, expected)
if __name__ == '__main__':
unittest.main()