From e5d78b7503524cd2ad2a04a6c3b44cadb91fed5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Colomb?= Date: Sat, 17 Aug 2024 20:43:39 +0200 Subject: [PATCH 1/7] 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. --- test/sample.eds | 7 +------ test/test_eds.py | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/test/sample.eds b/test/sample.eds index 3c1bbcf9..be2e3c8c 100644 --- a/test/sample.eds +++ b/test/sample.eds @@ -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 diff --git a/test/test_eds.py b/test/test_eds.py index 986010f4..12c3c2fa 100644 --- a/test/test_eds.py +++ b/test/test_eds.py @@ -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'] From 86c3350937f07e5e6baf2dfd0784167c54f66e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Colomb?= Date: Sat, 17 Aug 2024 20:31:42 +0200 Subject: [PATCH 2/7] 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. --- test/sample.eds | 53 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/test/sample.eds b/test/sample.eds index be2e3c8c..1afe9965 100644 --- a/test/sample.eds +++ b/test/sample.eds @@ -118,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 From daf8ca68f5712673b03a7cb6b35e138a8424a1ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Colomb?= Date: Sat, 17 Aug 2024 20:03:45 +0200 Subject: [PATCH 3/7] Add test for SdoArray dynamically generated member variables. --- test/test_sdo.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/test_sdo.py b/test/test_sdo.py index d3d0dfb6..10b6ad60 100644 --- a/test/test_sdo.py +++ b/test/test_sdo.py @@ -10,6 +10,23 @@ 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 + + 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 From 5cbb00ef9129643be462ef5feab271e701947802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Colomb?= Date: Sat, 17 Aug 2024 20:31:03 +0200 Subject: [PATCH 4/7] Add test for SdoArray length and iteration count. --- test/test_sdo.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/test_sdo.py b/test/test_sdo.py index 10b6ad60..8b445986 100644 --- a/test/test_sdo.py +++ b/test/test_sdo.py @@ -20,6 +20,17 @@ def setUp(self): node = canopen.LocalNode(1, SAMPLE_EDS) self.sdo_node = node.sdo + 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] From 30c407127b12bcdfc7afce2449aa3811e8da3e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Colomb?= Date: Sat, 17 Aug 2024 20:03:45 +0200 Subject: [PATCH 5/7] Add test for SdoRecord length and iteration count. --- test/test_sdo.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/test_sdo.py b/test/test_sdo.py index 8b445986..d931ca9e 100644 --- a/test/test_sdo.py +++ b/test/test_sdo.py @@ -20,6 +20,15 @@ def setUp(self): node = canopen.LocalNode(1, SAMPLE_EDS) self.sdo_node = node.sdo + def test_record_iter_length(self): + """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] From 76d16e72b77506f3e22513e2590a8d5b4707491e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Colomb?= Date: Sat, 17 Aug 2024 22:36:09 +0200 Subject: [PATCH 6/7] Fix docstring quotes. --- test/test_sdo.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_sdo.py b/test/test_sdo.py index d931ca9e..993d4acc 100644 --- a/test/test_sdo.py +++ b/test/test_sdo.py @@ -23,7 +23,8 @@ def setUp(self): def test_record_iter_length(self): """Assume the "highest subindex supported" entry is not counted. - Sub-objects without an OD entry should be skipped as well.""" + 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) From d38377c6dea60f15c7316ba3e0d576b7082afe74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Colomb?= Date: Sat, 17 Aug 2024 22:57:38 +0200 Subject: [PATCH 7/7] Expect failure Co-authored-by: Erlend E. Aasland --- test/test_sdo.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_sdo.py b/test/test_sdo.py index 993d4acc..212fc7f5 100644 --- a/test/test_sdo.py +++ b/test/test_sdo.py @@ -20,6 +20,7 @@ def setUp(self): node = canopen.LocalNode(1, SAMPLE_EDS) self.sdo_node = node.sdo + @unittest.expectedFailure def test_record_iter_length(self): """Assume the "highest subindex supported" entry is not counted.