Skip to content

Commit 3f0f264

Browse files
authored
Merge pull request #1204 from Tbruno25/1175_fix-int-conversion
Add str conversion to config vals
2 parents 2e24af0 + 07855c8 commit 3f0f264

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

can/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def _create_bus_config(config: Dict[str, Any]) -> typechecking.BusConfig:
232232
"btr1",
233233
):
234234
if key in config:
235-
timing_conf[key] = int(config[key], base=0)
235+
timing_conf[key] = int(str(config[key]), base=0)
236236
del config[key]
237237
if timing_conf:
238238
timing_conf["bitrate"] = config["bitrate"]

test/test_util.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import unittest
22
import warnings
33

4-
from can.util import _rename_kwargs
4+
from can.util import _create_bus_config, _rename_kwargs
55

66

77
class RenameKwargsTest(unittest.TestCase):
@@ -47,3 +47,18 @@ def test_with_new_and_alias_present(self):
4747
aliases = {"old_a": "a", "old_b": "b", "z": None}
4848
with self.assertRaises(TypeError):
4949
self._test(kwargs, aliases)
50+
51+
52+
class TestBusConfig(unittest.TestCase):
53+
base_config = dict(interface="socketcan", bitrate=500_000)
54+
55+
def test_timing_can_use_int(self):
56+
"""
57+
Test that an exception is not raised when using
58+
integers for timing values in config.
59+
"""
60+
timing_conf = dict(tseg1=5, tseg2=10, sjw=25)
61+
try:
62+
_create_bus_config({**self.base_config, **timing_conf})
63+
except TypeError as e:
64+
self.fail(e)

0 commit comments

Comments
 (0)