Exemplo n.º 1
0
 def test_decode_by_type_field_table_value(self):
     value = decode.by_type(self.FIELD_TBL, 'table')[1]
     for key in value.keys():
         if isinstance(value[key], float):
             self.assertAlmostEqual(round(value[key], 3),
                                    round(self.FIELD_TBL_VALUE[key], 3))
         else:
             self.assertEqual(value[key], self.FIELD_TBL_VALUE[key])
Exemplo n.º 2
0
 def test_decode_by_type_field_array_value(self):
     value = decode.by_type(self.FIELD_ARR, 'array')[1]
     for position in range(0, len(value)):
         if isinstance(value[position], float):
             self.assertAlmostEqual(round(value[position], 3),
                                    round(self.FIELD_ARR_VALUE[position],
                                          3))
         else:
             self.assertEqual(value[position],
                              self.FIELD_ARR_VALUE[position])
Exemplo n.º 3
0
 def test_decode_by_type_decimal_data_type(self):
     self.assertIsInstance(
         decode.by_type(b'\x05\x00\x04\xcb/', 'decimal')[1],
         decimal.Decimal)
Exemplo n.º 4
0
 def test_decode_by_type_timestamp_data_type(self):
     value = b'\x00\x00\x00\x00Ec)\x92'
     self.assertIsInstance(decode.by_type(value, 'timestamp')[1],
                           time.struct_time)
Exemplo n.º 5
0
 def test_decode_by_type_short_bytes_consumed(self):
     value = b'\x7f\xff'
     self.assertEqual(decode.by_type(value, 'short')[0], 2)
Exemplo n.º 6
0
 def test_decode_by_type_longstr_value(self):
     value = b'\x00\x00\x00\n0123456789'
     self.assertEqual(decode.by_type(value, 'longstr')[1], b'0123456789')
Exemplo n.º 7
0
 def test_decode_by_type_long_long_value(self):
     value = b'\x7f\xff\xff\xff\xff\xff\xff\xf8'
     self.assertEqual(decode.by_type(value, 'longlong')[1],
                      9223372036854775800)
Exemplo n.º 8
0
 def test_decode_by_type_floating_point_value(self):
     value = b'@I\x0f\xd0'
     self.assertEqual(round(decode.by_type(value, 'float')[1], 5),
                      round(float(3.14159), 5))
Exemplo n.º 9
0
 def test_decode_by_type_floating_point_value(self):
     value = b'@I\x0f\xd0'
     self.assertEqual(round(decode.by_type(value, 'float')[1], 5),
                      round(float(3.14159), 5))
Exemplo n.º 10
0
 def test_decode_by_type_float_bytes_consumed(self):
     self.assertEqual(decode.by_type(b'@I\x0f\xd0', 'float')[0], 4)
Exemplo n.º 11
0
 def test_decode_by_type_floating_point_data_type(self):
     self.assertIsInstance(decode.by_type(b'@I\x0f\xd0', 'float')[1], float)
Exemplo n.º 12
0
 def test_decode_by_type_double_value(self):
     value = b'C\x0f\xd8\x91\x14\xb9\xc3\x98'
     self.assertEqual(
         decode.by_type(value, 'double')[1], 1120480238450803.0)
Exemplo n.º 13
0
 def test_decode_by_type_double_bytes_consumed(self):
     value = b'C\x0f\xd8\x91\x14\xb9\xc3\x98'
     self.assertEqual(decode.by_type(value, 'double')[0], 8)
Exemplo n.º 14
0
 def test_decode_by_type_double_data_type(self):
     value = b'C\x0f\xd8\x91\x14\xb9\xc3\x98'
     self.assertIsInstance(decode.by_type(value, 'double')[1], float)
Exemplo n.º 15
0
 def test_decode_by_type_decimal_value(self):
     self.assertEqual(
         round(float(decode.by_type(b'\x05\x00\x04\xcb/', 'decimal')[1]),
               5), round(float(decimal.Decimal('3.14159')), 5))
Exemplo n.º 16
0
 def test_decode_by_type_decimal_data_type(self):
     self.assertIsInstance(decode.by_type(b'\x05\x00\x04\xcb/',
                                          'decimal')[1],
                           decimal.Decimal)
Exemplo n.º 17
0
 def test_decode_by_type_floating_point_bytes_consumed(self):
     self.assertEqual(decode.by_type(b'@I\x0f\xd0', 'float')[0], 4)
Exemplo n.º 18
0
 def test_decode_by_type_long_value(self):
     value = b'\x7f\xff\xff\xff'
     self.assertEqual(decode.by_type(value, 'long')[1], 2147483647)
Exemplo n.º 19
0
 def test_decode_by_type_long_long_bytes_consumed(self):
     value = b'\x7f\xff\xff\xff\xff\xff\xff\xf8'
     self.assertEqual(decode.by_type(value, 'longlong')[0], 8)
Exemplo n.º 20
0
 def test_decode_by_type_long_long_bytes_consumed(self):
     value = b'\x7f\xff\xff\xff\xff\xff\xff\xf8'
     self.assertEqual(decode.by_type(value, 'longlong')[0], 8)
Exemplo n.º 21
0
 def test_decode_by_type_longstr_data_type_with_unicode(self):
     value = b'\x00\x00\x00\x08Test \xe2\x9c\x88'
     self.assertIsInstance(decode.by_type(value, 'longstr')[1], bytes)
Exemplo n.º 22
0
 def test_decode_by_type_long_long_data_type_64bit(self):
     value = b'\x7f\xff\xff\xff\xff\xff\xff\xf8'
     self.assertIsInstance(decode.by_type(value, 'longlong')[1], int)
Exemplo n.º 23
0
 def test_decode_by_type_octet_data_type(self):
     self.assertIsInstance(decode.by_type(b'\xff', 'octet')[1], int)
Exemplo n.º 24
0
 def test_decode_by_type_long_long_value(self):
     value = b'\x7f\xff\xff\xff\xff\xff\xff\xf8'
     self.assertEqual(
         decode.by_type(value, 'longlong')[1], 9223372036854775800)
Exemplo n.º 25
0
 def test_decode_by_type_short_value(self):
     value = b'\x7f\xff'
     self.assertEqual(decode.by_type(value, 'short')[1], 32767)
Exemplo n.º 26
0
 def test_decode_by_type_longstr_bytes_consumed(self):
     value = b'\x00\x00\x00\n0123456789'
     self.assertEqual(decode.by_type(value, 'longstr')[0], 14)
Exemplo n.º 27
0
 def test_decode_by_type_field_array_bytes_consumed(self):
     self.assertEqual(decode.by_type(self.FIELD_ARR, 'array')[0],
                      len(self.FIELD_ARR))
Exemplo n.º 28
0
 def test_decode_by_type_longstr_data_type_with_unicode(self):
     value = b'\x00\x00\x00\x08Test \xe2\x9c\x88'
     self.assertIsInstance(decode.by_type(value, 'longstr')[1], str)
Exemplo n.º 29
0
 def test_decode_by_type_field_table_data_type(self):
     self.assertIsInstance(decode.by_type(self.FIELD_TBL,
                                          'table')[1], dict)
Exemplo n.º 30
0
 def test_decode_by_type_longstr_data_type(self):
     value = b'\x00\x00\x00\n0123456789'
     self.assertIsInstance(decode.by_type(value, 'longstr')[1], str)
Exemplo n.º 31
0
 def test_decode_by_type_decimal_bytes_consumed(self):
     value = b'\x05\x00\x04\xcb/'
     self.assertEqual(decode.by_type(value, 'decimal')[0], len(value))
Exemplo n.º 32
0
 def test_decode_by_type_longstr_value(self):
     value = b'\x00\x00\x00\n0123456789'
     self.assertEqual(decode.by_type(value, 'longstr')[1], '0123456789')
Exemplo n.º 33
0
 def test_decode_by_type_decimal_value(self):
     self.assertEqual(round(float(decode.by_type(b'\x05\x00\x04\xcb/',
                                                 'decimal')[1]), 5),
                      round(float(decimal.Decimal('3.14159')), 5))
Exemplo n.º 34
0
 def test_decode_by_type_octet_bytes_consumed(self):
     self.assertEqual(decode.by_type(b'\xff', 'octet')[0], 1)
Exemplo n.º 35
0
 def test_decode_by_type_floating_point_data_type(self):
     value = b'@I\x0f\xd0'
     self.assertIsInstance(decode.by_type(value, 'float')[1],
                           float)
Exemplo n.º 36
0
 def test_decode_by_type_octet_data_type(self):
     self.assertIsInstance(decode.by_type(b'\xff', 'octet')[1], int)
Exemplo n.º 37
0
 def test_decode_by_type_long_value(self):
     value = b'\x7f\xff\xff\xff'
     self.assertEqual(decode.by_type(value, 'long')[1], 2147483647)
Exemplo n.º 38
0
 def test_decode_by_type_octet_value(self):
     self.assertEqual(decode.by_type(b'\xff', 'octet')[1], 255)
Exemplo n.º 39
0
 def test_decode_by_type_long_long_data_type(self):
     value = b'\x7f\xff\xff\xff\xff\xff\xff\xf8'
     self.assertIsInstance(decode.by_type(value, 'longlong')[1], int)
Exemplo n.º 40
0
 def test_decode_by_type_short_bytes_consumed(self):
     value = b'\x7f\xff'
     self.assertEqual(decode.by_type(value, 'short')[0], 2)
Exemplo n.º 41
0
 def test_decode_by_type_longstr_bytes_consumed(self):
     value = b'\x00\x00\x00\n0123456789'
     self.assertEqual(decode.by_type(value, 'longstr')[0], 14)
Exemplo n.º 42
0
 def test_decode_by_type_short_data_type(self):
     value = b'\x7f\xff'
     self.assertIsInstance(decode.by_type(value, 'short')[1], int)
Exemplo n.º 43
0
 def test_decode_by_type_longstr_data_type(self):
     value = b'\x00\x00\x00\n0123456789'
     self.assertIsInstance(decode.by_type(value, 'longstr')[1], basestring)
Exemplo n.º 44
0
 def test_decode_by_type_short_value(self):
     value = b'\x7f\xff'
     self.assertEqual(decode.by_type(value, 'short')[1], 32767)
Exemplo n.º 45
0
 def test_decode_by_type_octet_bytes_consumed(self):
     self.assertEqual(decode.by_type(b'\xff', 'octet')[0], 1)
Exemplo n.º 46
0
 def test_decode_by_type_timestamp_bytes_consumed(self):
     value = b'\x00\x00\x00\x00Ec)\x92'
     self.assertEqual(decode.by_type(value, 'timestamp')[0], 8)
Exemplo n.º 47
0
 def test_decode_by_type_octet_value(self):
     self.assertEqual(decode.by_type(b'\xff', 'octet')[1], 255)
Exemplo n.º 48
0
 def test_decode_by_type_timestamp_data_type(self):
     value = b'\x00\x00\x00\x00Ec)\x92'
     self.assertIsInstance(
         decode.by_type(value, 'timestamp')[1], datetime.datetime)
Exemplo n.º 49
0
 def test_decode_by_type_short_data_type(self):
     value = b'\x7f\xff'
     self.assertIsInstance(decode.by_type(value, 'short')[1], int)
Exemplo n.º 50
0
 def test_decode_by_type_timestamp_value(self):
     value = b'\x00\x00\x00\x00Ec)\x92'
     self.assertEqual(
         decode.by_type(value, 'timestamp')[1],
         datetime.datetime(2006, 11, 21, 16, 30, 10))
Exemplo n.º 51
0
 def test_decode_by_type_timestamp_bytes_consumed(self):
     value = b'\x00\x00\x00\x00Ec)\x92'
     self.assertEqual(decode.by_type(value, 'timestamp')[0], 8)
Exemplo n.º 52
0
 def test_decode_by_type_void(self):
     self.assertIsNone(decode.by_type(b'', 'void')[1])
Exemplo n.º 53
0
 def test_decode_by_type_timestamp_value(self):
     value = b'\x00\x00\x00\x00Ec)\x92'
     self.assertEqual(decode.by_type(value, 'timestamp')[1],
                      time.struct_time((2006, 11, 21,
                                        16, 30, 10, 1, 325, 0)))
Exemplo n.º 54
0
 def test_decode_by_type_field_array_bytes_consumed(self):
     self.assertEqual(
         decode.by_type(self.FIELD_ARR, 'array')[0], len(self.FIELD_ARR))
Exemplo n.º 55
0
 def test_decode_by_type_field_array_data_type(self):
     self.assertIsInstance(decode.by_type(self.FIELD_ARR,
                                          'array')[1], list)
Exemplo n.º 56
0
 def test_decode_by_type_field_array_data_type(self):
     self.assertIsInstance(decode.by_type(self.FIELD_ARR, 'array')[1], list)
Exemplo n.º 57
0
 def test_decode_by_type_field_table_bytes_consumed(self):
     self.assertEqual(decode.by_type(self.FIELD_TBL, 'table')[0],
                      len(self.FIELD_TBL))
Exemplo n.º 58
0
 def test_decode_by_type_field_table_bytes_consumed(self):
     self.assertEqual(
         decode.by_type(self.FIELD_TBL, 'table')[0], len(self.FIELD_TBL))
Exemplo n.º 59
0
 def test_decode_by_type_boolean_true_data_type(self):
     self.assertIsInstance(decode.by_type(b'\x01', 'boolean')[1], bool)
Exemplo n.º 60
0
 def test_decode_by_type_decimal_bytes_consumed(self):
     value = b'\x05\x00\x04\xcb/'
     self.assertEqual(decode.by_type(value, 'decimal')[0], len(value))