Skip to content

Commit 3656059

Browse files
DALENCON StanislasDALENCON Stanislas
authored andcommitted
Add tests and some corrections according to PR suggestions.
1 parent 2afeefb commit 3656059

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

canopen/objectdictionary/eds.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ def import_eds(source, node_id):
3737

3838
for section in eds.sections():
3939
# Match dummy definitions
40-
match = re.match(r"^[D|d]ummy[U|u]sage$", section)
40+
match = re.match(r"^[Dd]ummy[Uu]sage$", section)
4141
if match is not None:
42-
for i in range(1,8):
42+
for i in range(1, 8):
4343
key = "Dummy%04d" % i
44-
if eds.getint(section,key) == 1:
44+
if eds.getint(section, key) == 1:
4545
var = objectdictionary.Variable(key, i, 0)
4646
var.data_type = i
4747
var.access_type = "const"

test/sample.eds

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ LSS_SerialNumber=0
3939
[DummyUsage]
4040
Dummy0001=0
4141
Dummy0002=0
42-
Dummy0003=0
42+
Dummy0003=1
4343
Dummy0004=0
4444
Dummy0005=0
4545
Dummy0006=0

test/test_eds.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,17 @@ def test_compact_subobj_parameter_name_with_percent(self):
7676
def test_sub_index_w_capital_s(self):
7777
name = self.od[0x3010][0].name
7878
self.assertEqual(name, 'Temperature')
79+
80+
def test_dummy_variable(self):
81+
var = self.od['Dummy0003']
82+
self.assertIsInstance(var, canopen.objectdictionary.Variable)
83+
self.assertEqual(var.index, 0x0003)
84+
self.assertEqual(var.subindex, 0)
85+
self.assertEqual(var.name, 'Dummy0003')
86+
self.assertEqual(var.data_type, canopen.objectdictionary.INTEGER16)
87+
self.assertEqual(var.access_type, 'const')
88+
self.assertEqual(len(var), 16)
89+
90+
def test_dummy_variable_undefined(self):
91+
with self.assertRaises(KeyError):
92+
var_undef = self.od['Dummy0001']

0 commit comments

Comments
 (0)