Skip to content

Commit 02ebc0c

Browse files
Add tests for bitrate parsing in import_eds() (#495)
1 parent f1315d3 commit 02ebc0c

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

canopen/objectdictionary/eds.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ def import_eds(source, node_id):
8585
pass
8686

8787
if eds.has_section("DeviceComissioning"):
88-
if val := eds.get("DeviceComissioning", "Baudrate", fallback=None):
89-
od.bitrate = int(val) * 1000
88+
if val := eds.getint("DeviceComissioning", "Baudrate", fallback=None):
89+
od.bitrate = val * 1000
9090

9191
if node_id is None:
9292
if val := eds.get("DeviceComissioning", "NodeID", fallback=None):

test/test_eds.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,21 @@ def test_load_explicit_nodeid(self):
8989
od = canopen.import_od(SAMPLE_EDS, node_id=3)
9090
self.assertEqual(od.node_id, 3)
9191

92+
def test_load_baudrate(self):
93+
od = canopen.import_od(SAMPLE_EDS)
94+
self.assertEqual(od.bitrate, 500_000)
95+
96+
def test_load_baudrate_fallback(self):
97+
import io
98+
99+
# Remove the Baudrate option.
100+
with open(SAMPLE_EDS) as f:
101+
lines = [L for L in f.readlines() if not L.startswith("Baudrate=")]
102+
with io.StringIO("".join(lines)) as buf:
103+
buf.name = "mock.eds"
104+
od = canopen.import_od(buf)
105+
self.assertIsNone(od.bitrate)
106+
92107
def test_variable(self):
93108
var = self.od['Producer heartbeat time']
94109
self.assertIsInstance(var, canopen.objectdictionary.ODVariable)

0 commit comments

Comments
 (0)