|
10 | 10 | RX = 2
|
11 | 11 |
|
12 | 12 |
|
| 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 | + |
13 | 52 | class TestSDO(unittest.TestCase):
|
14 | 53 | """
|
15 | 54 | Test SDO traffic by example. Most are taken from
|
|
0 commit comments