Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Verify some basic SDO record and array assumptions #539

Merged
merged 7 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 53 additions & 7 deletions test/sample.eds
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,7 @@ DataType=0x0007
AccessType=ro
PDOMapping=0

[1018sub3]
ParameterName=Revision number
ObjectType=0x7
DataType=0x0007
AccessType=ro
PDOMapping=0
; [1018sub3] left out for testing

[1018sub4]
ParameterName=Serial number
Expand All @@ -123,11 +118,62 @@ SupportedObjects=3
[1003]
ParameterName=Pre-defined error field
ObjectType=0x8
CompactSubObj=255
SubNumber=9

[1003sub0]
ParameterName=Number of errors
ObjectType=0x7
DataType=0x0005
AccessType=rw
DefaultValue=3
PDOMapping=0

[1003sub1]
ParameterName=Pre-defined error field_1
ObjectType=0x7
DataType=0x0007
AccessType=ro
DefaultValue=0
PDOMapping=0

; [1003sub2] left out for testing

[1003sub3]
ParameterName=Pre-defined error field_3
ObjectType=0x7
DataType=0x0007
AccessType=ro
DefaultValue=0
PDOMapping=0

[1003sub4]
ParameterName=Pre-defined error field_4
ObjectType=0x7
DataType=0x0007
AccessType=ro
DefaultValue=0
PDOMapping=0

[1003sub5]
ParameterName=Pre-defined error field_5
ObjectType=0x7
DataType=0x0007
AccessType=ro
DefaultValue=0
PDOMapping=0

; [1003sub6] left out for testing

[1003sub7]
ParameterName=Pre-defined error field_7
ObjectType=0x7
DataType=0x0007
AccessType=ro
DefaultValue=0
PDOMapping=0

; [1003sub8] left out for testing

[1008]
ParameterName=Manufacturer device name
ObjectType=0x7
Expand Down
2 changes: 1 addition & 1 deletion test/test_eds.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_relative_variable(self):
def test_record(self):
record = self.od['Identity object']
self.assertIsInstance(record, canopen.objectdictionary.ODRecord)
self.assertEqual(len(record), 5)
self.assertEqual(len(record), 4)
self.assertEqual(record.index, 0x1018)
self.assertEqual(record.name, 'Identity object')
var = record['Vendor-ID']
Expand Down
39 changes: 39 additions & 0 deletions test/test_sdo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,45 @@
RX = 2


class TestSDOVariables(unittest.TestCase):
"""Some basic assumptions on the behavior of SDO variable objects.

Mostly what is stated in the API docs.
"""

def setUp(self):
node = canopen.LocalNode(1, SAMPLE_EDS)
self.sdo_node = node.sdo

@unittest.expectedFailure
def test_record_iter_length(self):
acolomb marked this conversation as resolved.
Show resolved Hide resolved
"""Assume the "highest subindex supported" entry is not counted.

Sub-objects without an OD entry should be skipped as well.
"""
record = self.sdo_node[0x1018]
subs = sum(1 for _ in iter(record))
self.assertEqual(len(record), 3)
self.assertEqual(subs, 3)

def test_array_iter_length(self):
"""Assume the "highest subindex supported" entry is not counted."""
array = self.sdo_node[0x1003]
subs = sum(1 for _ in iter(array))
self.assertEqual(len(array), 3)
self.assertEqual(subs, 3)
# Simulate more entries getting added dynamically
array[0].set_data(b'\x08')
subs = sum(1 for _ in iter(array))
self.assertEqual(subs, 8)

def test_array_members_dynamic(self):
"""Check if sub-objects missing from OD entry are generated dynamically."""
array = self.sdo_node[0x1003]
for var in array.values():
self.assertIsInstance(var, canopen.sdo.SdoVariable)


class TestSDO(unittest.TestCase):
"""
Test SDO traffic by example. Most are taken from
Expand Down