示例#1
0
 def test_serialize_binary(self):
     self.assertEqual(self.serializer.serialize(Binary(b'\x01')),
                      {'B': b'\x01'})
示例#2
0
 def test_str(self):
     self.assertEqual(Binary(b'\x01').__str__(), b'\x01')
示例#3
0
 def test_repr(self):
     self.assertIn('Binary', repr(Binary(b'1')))
示例#4
0
 def test_integer_throws_error(self):
     with self.assertRaises(TypeError):
         Binary(1)
示例#5
0
 def test_not_equal(self):
     self.assertTrue(Binary(b'\x01') != b'\x02')
示例#6
0
 def test_bytearray_input(self):
     data = Binary(bytearray([1]))
     self.assertEqual(b'\x01', data)
     self.assertEqual(b'\x01', data.value)
示例#7
0
 def test_unicode_throws_error(self):
     with self.assertRaises(TypeError):
         Binary(u'\u00e9')
示例#8
0
 def test_non_ascii_bytes_input(self):
     # Binary data that is out of ASCII range
     data = Binary(b'\x88')
     self.assertEqual(b'\x88', data)
     self.assertEqual(b'\x88', data.value)
示例#9
0
 def test_bytes_input(self):
     data = Binary(b'\x01')
     self.assertEqual(b'\x01', data)
     self.assertEqual(b'\x01', data.value)
示例#10
0
 def test_deserialize_binary_set(self):
     self.assertEqual(
         self.deserializer.deserialize({'BS': [b'\x00', b'\x01']}),
         set([Binary(b'\x00'), Binary(b'\x01')]))
示例#11
0
 def test_deserialize_binary(self):
     self.assertEqual(self.deserializer.deserialize({'B': b'\x00'}),
                      Binary(b'\x00'))
示例#12
0
 def test_serialize_binary_set(self):
     serialized_value = self.serializer.serialize(
         set([Binary(b'\x01'), Binary(b'\x02')]))
     self.assertEqual(len(serialized_value), 1)
     self.assertIn('BS', serialized_value)
     self.assertCountEqual(serialized_value['BS'], [b'\x01', b'\x02'])