File tree 2 files changed +14
-2
lines changed
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]:
292
292
if isinstance (channel , int ):
293
293
return channel
294
294
if isinstance (channel , str ):
295
- match = re .match (r".*(\d+)$" , channel )
295
+ match = re .match (r".*? (\d+)$" , channel )
296
296
if match :
297
297
return int (match .group (1 ))
298
298
return None
Original file line number Diff line number Diff line change 3
3
import unittest
4
4
import warnings
5
5
6
- from can .util import _create_bus_config , _rename_kwargs
6
+ from can .util import _create_bus_config , _rename_kwargs , channel2int
7
7
8
8
9
9
class RenameKwargsTest (unittest .TestCase ):
@@ -64,3 +64,15 @@ def test_timing_can_use_int(self):
64
64
_create_bus_config ({** self .base_config , ** timing_conf })
65
65
except TypeError as e :
66
66
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