Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for bitrate parsing in import_eds() #495

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions canopen/objectdictionary/eds.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def import_eds(source, node_id):
pass

if eds.has_section("DeviceComissioning"):
if val := eds.get("DeviceComissioning", "Baudrate", fallback=None):
od.bitrate = int(val) * 1000
if val := eds.getint("DeviceComissioning", "Baudrate", fallback=None):
od.bitrate = val * 1000

if node_id is None:
if val := eds.get("DeviceComissioning", "NodeID", fallback=None):
Expand Down
15 changes: 15 additions & 0 deletions test/test_eds.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ def test_load_explicit_nodeid(self):
od = canopen.import_od(SAMPLE_EDS, node_id=3)
self.assertEqual(od.node_id, 3)

def test_load_baudrate(self):
od = canopen.import_od(SAMPLE_EDS)
self.assertEqual(od.bitrate, 500_000)

def test_load_baudrate_fallback(self):
import io

# Remove the Baudrate option.
with open(SAMPLE_EDS) as f:
lines = [L for L in f.readlines() if not L.startswith("Baudrate=")]
with io.StringIO("".join(lines)) as buf:
buf.name = "mock.eds"
od = canopen.import_od(buf)
self.assertIsNone(od.bitrate)

def test_variable(self):
var = self.od['Producer heartbeat time']
self.assertIsInstance(var, canopen.objectdictionary.ODVariable)
Expand Down
Loading