forked from hardbyte/python-can
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_interface_ixxat.py
More file actions
68 lines (53 loc) · 1.92 KB
/
Copy pathtest_interface_ixxat.py
File metadata and controls
68 lines (53 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
Unittest for ixxat interface.
Run only this test:
python setup.py test --addopts "--verbose -s test/test_interface_ixxat.py"
"""
import unittest
import can
class SoftwareTestCase(unittest.TestCase):
"""
Test cases that test the software only and do not rely on an existing/connected hardware.
"""
def setUp(self):
try:
bus = can.Bus(interface="ixxat", channel=0)
bus.shutdown()
except ImportError:
raise(unittest.SkipTest())
def tearDown(self):
pass
def test_bus_creation(self):
# channel must be >= 0
with self.assertRaises(ValueError):
bus = can.Bus(interface="ixxat", channel=-1)
# rxFifoSize must be > 0
with self.assertRaises(ValueError):
bus = can.Bus(interface="ixxat", channel=0, rxFifoSize=0)
# txFifoSize must be > 0
with self.assertRaises(ValueError):
bus = can.Bus(interface="ixxat", channel=0, txFifoSize=0)
class HardwareTestCase(unittest.TestCase):
"""
Test cases that rely on an existing/connected hardware.
"""
def setUp(self):
try:
bus = can.Bus(interface="ixxat", channel=0)
bus.shutdown()
except ImportError:
raise(unittest.SkipTest())
def tearDown(self):
pass
def test_bus_creation(self):
# non-existent channel -> use arbitrary high value
with self.assertRaises(can.CanInitializationError):
bus = can.Bus(interface="ixxat", channel=0xFFFF)
def test_send_after_shutdown(self):
bus = can.Bus(interface="ixxat", channel=0)
msg = can.Message(arbitration_id=0x3FF, dlc=0)
bus.shutdown()
with self.assertRaises(can.CanOperationError):
bus.send(msg)
if __name__ == '__main__':
unittest.main()