Exemple #1
0
 def setUp(self):
     self.patcher = patch('serial.Serial')
     self.mock_serial = self.patcher.start()
     self.serial_dummy = SerialDummy()
     self.mock_serial.return_value.write = self.serial_dummy.write
     self.mock_serial.return_value.read = self.serial_dummy.read
     self.addCleanup(self.patcher.stop)
     self.bus = SerialBus('bus')
Exemple #2
0
class SimpleSerialLoopTest(unittest.TestCase, SimpleSerialTestBase):
    def __init__(self, *args, **kwargs):
        unittest.TestCase.__init__(self, *args, **kwargs)
        SimpleSerialTestBase.__init__(self)

    def setUp(self):
        self.bus = SerialBus("loop://", timeout=TIMEOUT)

    def tearDown(self):
        self.bus.shutdown()
Exemple #3
0
class SimpleSerialLoopTest(unittest.TestCase, SimpleSerialTestBase):

    def __init__(self, *args, **kwargs):
        unittest.TestCase.__init__(self, *args, **kwargs)
        SimpleSerialTestBase.__init__(self)

    def setUp(self):
        self.bus = SerialBus('loop://')

    def tearDown(self):
        self.bus.shutdown()
Exemple #4
0
 def setUp(self):
     self.patcher = patch("serial.Serial")
     self.mock_serial = self.patcher.start()
     self.serial_dummy = SerialDummy()
     self.mock_serial.return_value.write = self.serial_dummy.write
     self.mock_serial.return_value.read = self.serial_dummy.read
     self.addCleanup(self.patcher.stop)
     self.bus = SerialBus("bus", timeout=TIMEOUT)
Exemple #5
0
 def setUp(self):
     self.bus = SerialBus("loop://", timeout=TIMEOUT)
Exemple #6
0
 def setUp(self):
     self.bus = SerialBus('loop://')
Exemple #7
0
 def setUp(self):
     self.bus = SerialBus('loop://')
Exemple #8
0
class SimpleSerialTest(unittest.TestCase):
    MAX_TIMESTAMP = 0xFFFFFFFF / 1000

    def setUp(self):
        self.patcher = patch('serial.Serial')
        self.mock_serial = self.patcher.start()
        self.serial_dummy = SerialDummy()
        self.mock_serial.return_value.write = self.serial_dummy.write
        self.mock_serial.return_value.read = self.serial_dummy.read
        self.addCleanup(self.patcher.stop)
        self.bus = SerialBus('bus')

    def tearDown(self):
        self.serial_dummy.reset()

    def test_rx_tx_min_max_data(self):
        """
        Tests the transfer from 0x00 to 0xFF for a 1 byte payload
        """
        for b in range(0, 255):
            msg = can.Message(data=[b])
            self.bus.send(msg)
            msg_receive = self.bus.recv()
            self.assertEqual(msg, msg_receive)

    def test_rx_tx_min_max_dlc(self):
        """
        Tests the transfer from a 1 - 8 byte payload
        """
        payload = bytearray()
        for b in range(1, 9):
            payload.append(0)
            msg = can.Message(data=payload)
            self.bus.send(msg)
            msg_receive = self.bus.recv()
            self.assertEqual(msg, msg_receive)

    def test_rx_tx_data_none(self):
        """
        Tests the transfer without payload
        """
        msg = can.Message(data=None)
        self.bus.send(msg)
        msg_receive = self.bus.recv()
        self.assertEqual(msg, msg_receive)

    def test_rx_tx_min_id(self):
        """
        Tests the transfer with the lowest arbitration id
        """
        msg = can.Message(arbitration_id=0)
        self.bus.send(msg)
        msg_receive = self.bus.recv()
        self.assertEqual(msg, msg_receive)

    def test_rx_tx_max_id(self):
        """
        Tests the transfer with the highest arbitration id
        """
        msg = can.Message(arbitration_id=536870911)
        self.bus.send(msg)
        msg_receive = self.bus.recv()
        self.assertEqual(msg, msg_receive)

    def test_rx_tx_max_timestamp(self):
        """
        Tests the transfer with the highest possible timestamp
        """

        msg = can.Message(timestamp=self.MAX_TIMESTAMP)
        self.bus.send(msg)
        msg_receive = self.bus.recv()
        self.assertEqual(msg, msg_receive)
        self.assertEqual(msg.timestamp, msg_receive.timestamp)

    def test_rx_tx_max_timestamp_error(self):
        """
        Tests for an exception with an out of range timestamp (max + 1)
        """
        msg = can.Message(timestamp=self.MAX_TIMESTAMP + 1)
        self.assertRaises(ValueError, self.bus.send, msg)

    def test_rx_tx_min_timestamp(self):
        """
        Tests the transfer with the lowest possible timestamp
        """
        msg = can.Message(timestamp=0)
        self.bus.send(msg)
        msg_receive = self.bus.recv()
        self.assertEqual(msg, msg_receive)
        self.assertEqual(msg.timestamp, msg_receive.timestamp)

    def test_rx_tx_min_timestamp_error(self):
        """
        Tests for an exception with an out of range timestamp (min - 1)
        """
        msg = can.Message(timestamp=-1)
        self.assertRaises(ValueError, self.bus.send, msg)
Exemple #9
0
 def setUp(self):
     self.bus = SerialBus("loop://")