9
9
import sys
10
10
11
11
from can .interfaces .ixxat import IXXATBus
12
+ from can .exceptions import CanInterfaceNotImplementedError
12
13
13
14
14
15
class SoftwareTestCase (unittest .TestCase ):
@@ -38,8 +39,12 @@ def test_bus_creation(self):
38
39
can .Bus (interface = "ixxat" , channel = 0xFFFF )
39
40
40
41
def test_adapter_enumeration (self ):
41
- # Enumeration of adapters should always work and the result should support len and be iterable
42
- adapters = IXXATBus .list_adapters ()
42
+ # Enumeration of adapters should always work (if the driver is installed) and the result should support len and be iterable
43
+ try :
44
+ adapters = IXXATBus .list_adapters ()
45
+ except CanInterfaceNotImplementedError :
46
+ raise unittest .SkipTest ("Maybe the driver is not installed." )
47
+
43
48
n = 0
44
49
for adapter in adapters :
45
50
n += 1
@@ -58,20 +63,28 @@ def setUp(self):
58
63
59
64
def test_bus_creation (self ):
60
65
# Test the enumeration of all adapters by opening and closing each adapter
61
- adapters = IXXATBus .list_adapters ()
66
+ try :
67
+ adapters = IXXATBus .list_adapters ()
68
+ except CanInterfaceNotImplementedError :
69
+ raise unittest .SkipTest ("Maybe the driver is not installed." )
70
+
62
71
for adapter in adapters :
63
72
bus = can .Bus (interface = "ixxat" , adapter = adapter )
64
73
bus .shutdown ()
65
74
66
75
def test_send_after_shutdown (self ):
67
76
# At least one adapter is needed, skip the test if none can be found
68
- adapters = IXXATBus .list_adapters ()
77
+ try :
78
+ adapters = IXXATBus .list_adapters ()
79
+ except CanInterfaceNotImplementedError :
80
+ raise unittest .SkipTest ("Maybe the driver is not installed." )
81
+
69
82
if len (adapters ) == 0 :
70
83
raise unittest .SkipTest ("No adapters found" )
71
84
72
85
bus = can .Bus (interface = "ixxat" , channel = 0 )
73
86
msg = can .Message (arbitration_id = 0x3FF , dlc = 0 )
74
- # Intentionally close the bus now and try to send afterwards. This should lead to an Exception
87
+ # Intentionally close the bus now and try to send afterwards. This should lead to an CanOperationError
75
88
bus .shutdown ()
76
89
with self .assertRaises (can .CanOperationError ):
77
90
bus .send (msg )
0 commit comments