Skip to content

Commit 273bab1

Browse files
authored
Tests: Verify some basic SDO record and array assumptions (#539)
* Remove one of the sub-objects in a record for testing. Adjust the EDS test accordingly, since the record length only counts sub-objects that have an actual description. * Flesh out the Pre-defined error field object in sample.eds. Switch from CompactSubObj to actual sub-entries. Leave out some of the sub-entries, targeting specific SDO tests. * Add test for SdoArray dynamically generated member variables. * Add test for SdoArray length and iteration count. * Add test for SdoRecord length and iteration count. * Expect failure on last added test.
1 parent 210374a commit 273bab1

File tree

3 files changed

+93
-8
lines changed

3 files changed

+93
-8
lines changed

test/sample.eds

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,7 @@ DataType=0x0007
100100
AccessType=ro
101101
PDOMapping=0
102102

103-
[1018sub3]
104-
ParameterName=Revision number
105-
ObjectType=0x7
106-
DataType=0x0007
107-
AccessType=ro
108-
PDOMapping=0
103+
; [1018sub3] left out for testing
109104

110105
[1018sub4]
111106
ParameterName=Serial number
@@ -123,11 +118,62 @@ SupportedObjects=3
123118
[1003]
124119
ParameterName=Pre-defined error field
125120
ObjectType=0x8
126-
CompactSubObj=255
121+
SubNumber=9
122+
123+
[1003sub0]
124+
ParameterName=Number of errors
125+
ObjectType=0x7
126+
DataType=0x0005
127+
AccessType=rw
128+
DefaultValue=3
129+
PDOMapping=0
130+
131+
[1003sub1]
132+
ParameterName=Pre-defined error field_1
133+
ObjectType=0x7
134+
DataType=0x0007
135+
AccessType=ro
136+
DefaultValue=0
137+
PDOMapping=0
138+
139+
; [1003sub2] left out for testing
140+
141+
[1003sub3]
142+
ParameterName=Pre-defined error field_3
143+
ObjectType=0x7
144+
DataType=0x0007
145+
AccessType=ro
146+
DefaultValue=0
147+
PDOMapping=0
148+
149+
[1003sub4]
150+
ParameterName=Pre-defined error field_4
151+
ObjectType=0x7
152+
DataType=0x0007
153+
AccessType=ro
154+
DefaultValue=0
155+
PDOMapping=0
156+
157+
[1003sub5]
158+
ParameterName=Pre-defined error field_5
159+
ObjectType=0x7
160+
DataType=0x0007
161+
AccessType=ro
162+
DefaultValue=0
163+
PDOMapping=0
164+
165+
; [1003sub6] left out for testing
166+
167+
[1003sub7]
168+
ParameterName=Pre-defined error field_7
169+
ObjectType=0x7
127170
DataType=0x0007
128171
AccessType=ro
172+
DefaultValue=0
129173
PDOMapping=0
130174

175+
; [1003sub8] left out for testing
176+
131177
[1008]
132178
ParameterName=Manufacturer device name
133179
ObjectType=0x7

test/test_eds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def test_relative_variable(self):
121121
def test_record(self):
122122
record = self.od['Identity object']
123123
self.assertIsInstance(record, canopen.objectdictionary.ODRecord)
124-
self.assertEqual(len(record), 5)
124+
self.assertEqual(len(record), 4)
125125
self.assertEqual(record.index, 0x1018)
126126
self.assertEqual(record.name, 'Identity object')
127127
var = record['Vendor-ID']

test/test_sdo.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,45 @@
1010
RX = 2
1111

1212

13+
class TestSDOVariables(unittest.TestCase):
14+
"""Some basic assumptions on the behavior of SDO variable objects.
15+
16+
Mostly what is stated in the API docs.
17+
"""
18+
19+
def setUp(self):
20+
node = canopen.LocalNode(1, SAMPLE_EDS)
21+
self.sdo_node = node.sdo
22+
23+
@unittest.expectedFailure
24+
def test_record_iter_length(self):
25+
"""Assume the "highest subindex supported" entry is not counted.
26+
27+
Sub-objects without an OD entry should be skipped as well.
28+
"""
29+
record = self.sdo_node[0x1018]
30+
subs = sum(1 for _ in iter(record))
31+
self.assertEqual(len(record), 3)
32+
self.assertEqual(subs, 3)
33+
34+
def test_array_iter_length(self):
35+
"""Assume the "highest subindex supported" entry is not counted."""
36+
array = self.sdo_node[0x1003]
37+
subs = sum(1 for _ in iter(array))
38+
self.assertEqual(len(array), 3)
39+
self.assertEqual(subs, 3)
40+
# Simulate more entries getting added dynamically
41+
array[0].set_data(b'\x08')
42+
subs = sum(1 for _ in iter(array))
43+
self.assertEqual(subs, 8)
44+
45+
def test_array_members_dynamic(self):
46+
"""Check if sub-objects missing from OD entry are generated dynamically."""
47+
array = self.sdo_node[0x1003]
48+
for var in array.values():
49+
self.assertIsInstance(var, canopen.sdo.SdoVariable)
50+
51+
1352
class TestSDO(unittest.TestCase):
1453
"""
1554
Test SDO traffic by example. Most are taken from

0 commit comments

Comments
 (0)