Exemplo n.º 1
0
 def test_composite_load_to_value(self):
     """Test load to value when there are many types involved."""
     values = [2032018, 15.409999847]
     load = ['\x92', '\x01', '\x1f', '\x00', '\\', '\x8f', 'v', 'A']
     func = Function(1, [Types.T_UINT8], [Types.T_UINT32, Types.T_FLOAT])
     self.assertEqual(func.load_to_value(load)[0], values[0])
     self.assertAlmostEqual(func.load_to_value(load)[1], values[1])
Exemplo n.º 2
0
 def test_arr_float_value_to_load(self):
     """Test value to load method."""
     value = [1.0, 2.0]
     expected_load = []
     for v in value:
         expected_load.extend(list(map(chr, struct.pack('<f', v))))
     func = Function(1, [Types.T_FLOAT, Types.T_FLOAT], [Types.T_UINT8])
     self.assertEqual(func.value_to_load(value), expected_load)
Exemplo n.º 3
0
    def test_string_value_to_load(self):
        """Test value to load method."""
        value = 'V0.07 2018-03'
        expected_load = [
            'V', '0', '.', '0', '7', ' ', '2', '0', '1', '8', '-', '0', '3',
            '\x00', '\x00'
        ]

        func = Function(1, [Types.T_CHAR for _ in range(15)], [Types.T_UINT8])
        self.assertEqual(func.value_to_load(value), expected_load)
Exemplo n.º 4
0
    def test_string_load_to_value(self):
        """Test load to value conversion method."""
        load = [
            'V', '0', '.', '0', '7', ' ', '2', '0', '1', '8', '\x00', '\x00',
            '\x00', '\x00', '\x00'
        ]

        expected_value = [
            b'V', b'0', b'.', b'0', b'7', b' ', b'2', b'0', b'1', b'8',
            b'\x00', b'\x00', b'\x00', b'\x00', b'\x00'
        ]
        func = Function(1, [Types.T_UINT8], [Types.T_CHAR for _ in range(15)])
        self.assertEqual(func.load_to_value(load), expected_value)
Exemplo n.º 5
0
 def setUp(self):
     """Set commons for all tests."""
     self.serial = Mock()
     self.entities = Mock()
     self.entities.functions = [
         Function(0, [Types.T_FLOAT], [Types.T_UINT8]),
     ]
     self.bsmp = BSMP(self.serial, 1, self.entities)
Exemplo n.º 6
0
 def test_arr_float_load_to_value(self):
     """Test load to value conversion method."""
     load = ['\x00', '\x00', '\x80', '?', '\x00', '\x00', '\x00', '\x00']
     expected_value = [1.0, 0.0]
     func = Function(1, [Types.T_UINT8], [Types.T_FLOAT, Types.T_FLOAT])
     self.assertEqual(func.load_to_value(load), expected_value)
Exemplo n.º 7
0
 def test_float_load_to_value(self):
     """Test load to value conversion method."""
     load = [chr(v) for v in struct.pack('<f', 10.5)]
     expected_value = 10.5
     func = Function(1, [Types.T_UINT8], [Types.T_FLOAT])
     self.assertEqual(func.load_to_value(load), expected_value)
Exemplo n.º 8
0
 def test_int_load_to_value(self):
     """Test load to value conversion method."""
     expected_value = 1
     load = [chr(1)]
     func = Function(1, [Types.T_UINT8], [Types.T_UINT8])
     self.assertEqual(func.load_to_value(load), expected_value)
Exemplo n.º 9
0
 def test_empty_load_to_value(self):
     """Test empty list is returned."""
     ret = Function(1, [Types.T_UINT8], [Types.T_UINT8]).load_to_value([])
     self.assertIsNone(ret)
Exemplo n.º 10
0
 def test_composite_value_to_load(self):
     """Test value to load method when there are many types involved."""
     values = [2032018, 15.41]
     load = ['\x92', '\x01', '\x1f', '\x00', '\\', '\x8f', 'v', 'A']
     func = Function(1, [Types.T_UINT32, Types.T_FLOAT], [Types.T_UINT8])
     self.assertEqual(func.value_to_load(values), load)
Exemplo n.º 11
0
 def test_float_value_to_load(self):
     """Test value to load method."""
     value = 10.5
     expected_load = [chr(b) for b in struct.pack('<f', value)]
     func = Function(1, [Types.T_FLOAT], [Types.T_UINT8])
     self.assertEqual(func.value_to_load(value), expected_load)
Exemplo n.º 12
0
 def test_strange_value_to_load(self):
     """Test empty list is returned."""
     with self.assertRaises(TypeError):
         Function(1, [Types.T_UINT16], [Types.T_UINT16]).value_to_load(1.5)
     with self.assertRaises(TypeError):
         Function(1, [Types.T_CHAR], [Types.T_UINT16]).value_to_load(15)
Exemplo n.º 13
0
 def test_null_value_to_load(self):
     """Test empty list is returned."""
     ret = \
         Function(1, [Types.T_UINT16], [Types.T_UINT16]).value_to_load(None)
     self.assertEqual(ret, [])
Exemplo n.º 14
0
 def test_big_putput_size(self):
     """Test output size bigger than 0."""
     with self.assertRaises(ValueError):
         Function(1, [Types.T_UINT16], [Types.T_UINT16 for _ in range(44)])