forked from hardbyte/python-can
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontextmanager_test.py
More file actions
41 lines (31 loc) · 1.13 KB
/
contextmanager_test.py
File metadata and controls
41 lines (31 loc) · 1.13 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
#!/usr/bin/env python
# coding: utf-8
"""
This module tests the context manager of Bus and Notifier classes
"""
import unittest
import can
class ContextManagerTest(unittest.TestCase):
def setUp(self):
data = [0, 1, 2, 3, 4, 5, 6, 7]
self.msg_send = can.Message(
is_extended_id=False, arbitration_id=0x100, data=data
)
def test_open_buses(self):
with can.Bus(interface="virtual") as bus_send, can.Bus(
interface="virtual"
) as bus_recv:
bus_send.send(self.msg_send)
msg_recv = bus_recv.recv()
# Receiving a frame with data should evaluate msg_recv to True
self.assertTrue(msg_recv)
def test_use_closed_bus(self):
with can.Bus(interface="virtual") as bus_send, can.Bus(
interface="virtual"
) as bus_recv:
bus_send.send(self.msg_send)
# Receiving a frame after bus has been closed should raise a CanException
self.assertRaises(can.CanError, bus_recv.recv)
self.assertRaises(can.CanError, bus_send.send, self.msg_send)
if __name__ == "__main__":
unittest.main()