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])
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])
def test_decode_by_type_decimal_data_type(self): self.assertIsInstance( decode.by_type(b'\x05\x00\x04\xcb/', 'decimal')[1], decimal.Decimal)
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)
def test_decode_by_type_short_bytes_consumed(self): value = b'\x7f\xff' self.assertEqual(decode.by_type(value, 'short')[0], 2)
def test_decode_by_type_longstr_value(self): value = b'\x00\x00\x00\n0123456789' self.assertEqual(decode.by_type(value, 'longstr')[1], b'0123456789')
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)
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))
def test_decode_by_type_float_bytes_consumed(self): self.assertEqual(decode.by_type(b'@I\x0f\xd0', 'float')[0], 4)
def test_decode_by_type_floating_point_data_type(self): self.assertIsInstance(decode.by_type(b'@I\x0f\xd0', 'float')[1], float)
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)
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)
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)
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))
def test_decode_by_type_decimal_data_type(self): self.assertIsInstance(decode.by_type(b'\x05\x00\x04\xcb/', 'decimal')[1], decimal.Decimal)
def test_decode_by_type_floating_point_bytes_consumed(self): self.assertEqual(decode.by_type(b'@I\x0f\xd0', 'float')[0], 4)
def test_decode_by_type_long_value(self): value = b'\x7f\xff\xff\xff' self.assertEqual(decode.by_type(value, 'long')[1], 2147483647)
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)
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)
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)
def test_decode_by_type_octet_data_type(self): self.assertIsInstance(decode.by_type(b'\xff', 'octet')[1], int)
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)
def test_decode_by_type_short_value(self): value = b'\x7f\xff' self.assertEqual(decode.by_type(value, 'short')[1], 32767)
def test_decode_by_type_longstr_bytes_consumed(self): value = b'\x00\x00\x00\n0123456789' self.assertEqual(decode.by_type(value, 'longstr')[0], 14)
def test_decode_by_type_field_array_bytes_consumed(self): self.assertEqual(decode.by_type(self.FIELD_ARR, 'array')[0], len(self.FIELD_ARR))
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)
def test_decode_by_type_field_table_data_type(self): self.assertIsInstance(decode.by_type(self.FIELD_TBL, 'table')[1], dict)
def test_decode_by_type_longstr_data_type(self): value = b'\x00\x00\x00\n0123456789' self.assertIsInstance(decode.by_type(value, 'longstr')[1], str)
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))
def test_decode_by_type_longstr_value(self): value = b'\x00\x00\x00\n0123456789' self.assertEqual(decode.by_type(value, 'longstr')[1], '0123456789')
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))
def test_decode_by_type_octet_bytes_consumed(self): self.assertEqual(decode.by_type(b'\xff', 'octet')[0], 1)
def test_decode_by_type_floating_point_data_type(self): value = b'@I\x0f\xd0' self.assertIsInstance(decode.by_type(value, 'float')[1], float)
def test_decode_by_type_octet_value(self): self.assertEqual(decode.by_type(b'\xff', 'octet')[1], 255)
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)
def test_decode_by_type_short_data_type(self): value = b'\x7f\xff' self.assertIsInstance(decode.by_type(value, 'short')[1], int)
def test_decode_by_type_longstr_data_type(self): value = b'\x00\x00\x00\n0123456789' self.assertIsInstance(decode.by_type(value, 'longstr')[1], basestring)
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)
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)
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))
def test_decode_by_type_void(self): self.assertIsNone(decode.by_type(b'', 'void')[1])
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)))
def test_decode_by_type_field_array_bytes_consumed(self): self.assertEqual( decode.by_type(self.FIELD_ARR, 'array')[0], len(self.FIELD_ARR))
def test_decode_by_type_field_array_data_type(self): self.assertIsInstance(decode.by_type(self.FIELD_ARR, 'array')[1], list)
def test_decode_by_type_field_table_bytes_consumed(self): self.assertEqual(decode.by_type(self.FIELD_TBL, 'table')[0], len(self.FIELD_TBL))
def test_decode_by_type_field_table_bytes_consumed(self): self.assertEqual( decode.by_type(self.FIELD_TBL, 'table')[0], len(self.FIELD_TBL))
def test_decode_by_type_boolean_true_data_type(self): self.assertIsInstance(decode.by_type(b'\x01', 'boolean')[1], bool)