class SerializerTestCase(unittest.TestCase): def setUp(self): self.serial = Serializer() def test_serialize_bundle(self): """Test serializing a bundle.""" message = Message('/test', 5) bundle = Bundle(None, message) self.assertEqual(self.serial.serialize_bundle(bundle), b'#bundle\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x10/test\x00\x00\x00,i\x00\x00\x00\x00\x00\x05') def test_serialize_message(self): """Test serializing a message.""" message = Message('/test', 5) self.assertEqual(self.serial.serialize_message(message), b'/test\x00\x00\x00,i\x00\x00\x00\x00\x00\x05') def test_serialize_blob_str(self): """Test serializing a blob with a string input.""" self.assertEqual(self.serial.serialize_blob('test'), b'\x00\x00\x00\x04test') def test_serialize_blob_int(self): """Test serializing a blob with an integer input.""" self.assertEqual(self.serial.serialize_blob(5), b'\x00\x00\x00\x04\x00\x00\x00\x05') def test_serialize_float32(self): """Test serializing a float32.""" self.assertEqual(self.serial.serialize_float32(5.0), b'@\xa0\x00\x00') def test_serialize_int32(self): """Test serializing an int.""" self.assertEqual(self.serial.serialize_int32(5), b'\x00\x00\x00\x05') def test_serialize_string(self): """Test serializing a string.""" self.assertEqual(self.serial.serialize_string('test'), b'test\x00\x00\x00\x00') def test_serialize_timetag(self): """ Test serializing a timetag. Impossible to check the actual data without using the implementation. The length of the data is checked instead. """ data = time.time() timetag = TimeTag(data) self.assertEqual(len(self.serial.serialize_timetag(timetag)), 8) def test_serialize_timetag_immediate(self): """Test serializing a timetag for immediate.""" self.assertEqual(self.serial.serialize_timetag(None), b'\x00\x00\x00\x00\x00\x00\x00\x01')
def setUp(self): self.serial = Serializer()