File: zero_dlc_test.py

package info (click to toggle)
python-can 3.0.0%2Bgithub-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,892 kB
  • sloc: python: 8,014; makefile: 29; sh: 12
file content (51 lines) | stat: -rw-r--r-- 1,350 bytes parent folder | download
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
#!/usr/bin/env python
# coding: utf-8

"""
"""

from time import sleep
import unittest
import logging

import can

logging.getLogger(__file__).setLevel(logging.DEBUG)


class ZeroDLCTest(unittest.TestCase):

    def test_recv_non_zero_dlc(self):
        bus_send = can.interface.Bus(bustype='virtual')
        bus_recv = can.interface.Bus(bustype='virtual')
        data = [0, 1, 2, 3, 4, 5, 6, 7]
        msg_send = can.Message(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):
        bus_recv = can.interface.Bus(bustype='virtual')

        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):
        bus_send = can.interface.Bus(bustype='virtual')
        bus_recv = can.interface.Bus(bustype='virtual')
        msg_send = can.Message(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()