Exemplo n.º 1
0
    def test_019_test_device_id_byte_conversion_03(self):
        """
        Test converting a device_id value to its byte array value, then back
        to the device_id value
        """
        device_id = 0x01c4

        did_bytes = device_id_to_bytes(device_id)
        self.assertEqual(did_bytes, [0x01, 0xc4])

        new_device_id = device_id_join_bytes(did_bytes)
        self.assertEqual(new_device_id, device_id)
    def test_014_device_id_join_bytes(self):
        """ Test converting a list of device_id bytes into its original value.
        """
        device_id_bytes = [0x00, 0x00]
        device_id = devicebus.device_id_join_bytes(device_id_bytes)
        self.assertEquals(device_id, 0x0000)

        device_id_bytes = [0xff, 0xff]
        device_id = devicebus.device_id_join_bytes(device_id_bytes)
        self.assertEquals(device_id, 0xffff)

        device_id_bytes = [0x43, 0x21]
        device_id = devicebus.device_id_join_bytes(device_id_bytes)
        self.assertEquals(device_id, 0x4321)

        device_id_bytes = [0x00, 0x01]
        device_id = devicebus.device_id_join_bytes(device_id_bytes)
        self.assertEquals(device_id, 0x1)

        device_id_bytes = [0xa7, 0x2b]
        device_id = devicebus.device_id_join_bytes(device_id_bytes)
        self.assertEquals(device_id, 0xa72b)

        device_id_bytes = [0xef, 0x00]
        device_id = devicebus.device_id_join_bytes(device_id_bytes)
        self.assertEquals(device_id, 0xef00)
    def test_015_device_id_join_bytes(self):
        """ Test converting a list of device_id bytes into its original value.
        """
        device_id_bytes = []
        with self.assertRaises(ValueError):
            devicebus.device_id_join_bytes(device_id_bytes)

        device_id_bytes = [0x12]
        with self.assertRaises(ValueError):
            devicebus.device_id_join_bytes(device_id_bytes)

        device_id_bytes = [0x12, 0x34, 0x56]
        with self.assertRaises(ValueError):
            devicebus.device_id_join_bytes(device_id_bytes)

        device_id_bytes = 0x1234
        with self.assertRaises(ValueError):
            devicebus.device_id_join_bytes(device_id_bytes)