File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -292,7 +292,7 @@ def channel2int(channel: Optional[typechecking.Channel]) -> Optional[int]:
292292 if isinstance (channel , int ):
293293 return channel
294294 if isinstance (channel , str ):
295- match = re .match (r".*(\d+)$" , channel )
295+ match = re .match (r".*? (\d+)$" , channel )
296296 if match :
297297 return int (match .group (1 ))
298298 return None
Original file line number Diff line number Diff line change 33import unittest
44import warnings
55
6- from can .util import _create_bus_config , _rename_kwargs
6+ from can .util import _create_bus_config , _rename_kwargs , channel2int
77
88
99class RenameKwargsTest (unittest .TestCase ):
@@ -64,3 +64,15 @@ def test_timing_can_use_int(self):
6464 _create_bus_config ({** self .base_config , ** timing_conf })
6565 except TypeError as e :
6666 self .fail (e )
67+
68+
69+ class TestChannel2Int (unittest .TestCase ):
70+ def test_channel2int (self ) -> None :
71+ self .assertEqual (0 , channel2int ("can0" ))
72+ self .assertEqual (0 , channel2int ("vcan0" ))
73+ self .assertEqual (1 , channel2int ("vcan1" ))
74+ self .assertEqual (12 , channel2int ("vcan12" ))
75+ self .assertEqual (3 , channel2int (3 ))
76+ self .assertEqual (42 , channel2int ("42" ))
77+ self .assertEqual (None , channel2int ("can" ))
78+ self .assertEqual (None , channel2int ("can0a" ))
You can’t perform that action at this time.
0 commit comments