forked from hardbyte/python-can
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzero_dlc_test.py
More file actions
52 lines (37 loc) · 1.46 KB
/
Copy pathzero_dlc_test.py
File metadata and controls
52 lines (37 loc) · 1.46 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
#!/usr/bin/env python
""" """
import logging
import unittest
import can
logging.getLogger(__file__).setLevel(logging.DEBUG)
class ZeroDLCTest(unittest.TestCase):
def test_recv_non_zero_dlc(self):
with (
can.interface.Bus(interface="virtual") as bus_send,
can.interface.Bus(interface="virtual") as bus_recv,
):
data = [0, 1, 2, 3, 4, 5, 6, 7]
msg_send = can.Message(
is_extended_id=False, arbitration_id=0x100, data=data
)
bus_send.send(msg_send)
msg_recv = bus_recv.recv()
# Receiving a frame with data should evaluate msg_recv to True
self.assertTrue(msg_recv)
def test_recv_none(self):
with can.interface.Bus(interface="virtual") as bus_recv:
msg_recv = bus_recv.recv(timeout=0)
# Receiving nothing should evaluate msg_recv to False
self.assertFalse(msg_recv)
def test_recv_zero_dlc(self):
with (
can.interface.Bus(interface="virtual") as bus_send,
can.interface.Bus(interface="virtual") as bus_recv,
):
msg_send = can.Message(is_extended_id=False, arbitration_id=0x100, data=[])
bus_send.send(msg_send)
msg_recv = bus_recv.recv()
# Receiving a frame without data (dlc == 0) should evaluate msg_recv to True
self.assertTrue(msg_recv)
if __name__ == "__main__":
unittest.main()