Skip to content

Commit 7ab54ec

Browse files
committed
Properly test different access type return values.
Augment test_pdo_getitem() to not only check the mapped object values. What's more important is the type of object returned, and whether it is the correct object (identical to other access method results).
1 parent 120ae99 commit 7ab54ec

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

test/test_pdo.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,25 @@ def test_pdo_getitem(self):
5050
self.assertEqual(node.tpdo[1]['BOOLEAN value 2'].raw, True)
5151

5252
# Test different types of access
53-
self.assertEqual(node.pdo[0x1600]['INTEGER16 value'].raw, -3)
54-
self.assertEqual(node.pdo['INTEGER16 value'].raw, -3)
55-
self.assertEqual(node.pdo.tx[1]['INTEGER16 value'].raw, -3)
56-
self.assertEqual(node.pdo[0x2001].raw, -3)
57-
self.assertEqual(node.tpdo[0x2001].raw, -3)
58-
self.assertEqual(node.pdo[0x2002].raw, 0xf)
59-
self.assertEqual(node.pdo['0x2002'].raw, 0xf)
60-
self.assertEqual(node.tpdo[0x2002].raw, 0xf)
61-
self.assertEqual(node.pdo[0x1600][0x2002].raw, 0xf)
53+
by_mapping_record = node.pdo[0x1600]
54+
self.assertIsInstance(by_mapping_record, canopen.pdo.PdoMap)
55+
self.assertEqual(by_mapping_record['INTEGER16 value'].raw, -3)
56+
by_object_name = node.pdo['INTEGER16 value']
57+
self.assertIsInstance(by_object_name, canopen.pdo.PdoVariable)
58+
self.assertIs(by_object_name.od, node.object_dictionary['INTEGER16 value'])
59+
self.assertEqual(by_object_name.raw, -3)
60+
by_pdo_index = node.pdo.tx[1]
61+
self.assertIs(by_pdo_index, by_mapping_record)
62+
by_object_index = node.pdo[0x2001]
63+
self.assertIsInstance(by_object_index, canopen.pdo.PdoVariable)
64+
self.assertIs(by_object_index, by_object_name)
65+
by_object_index_tpdo = node.tpdo[0x2001]
66+
self.assertIs(by_object_index_tpdo, by_object_name)
67+
by_object_index = node.pdo[0x2002]
68+
self.assertEqual(by_object_index.raw, 0xf)
69+
self.assertIs(node.pdo['0x2002'], by_object_index)
70+
self.assertIs(node.tpdo[0x2002], by_object_index)
71+
self.assertIs(node.pdo[0x1600][0x2002], by_object_index)
6272

6373
def test_pdo_save(self):
6474
self.node.tpdo.save()

0 commit comments

Comments
 (0)