Ejemplo n.º 1
0
 def setUp(self):
     self.d = Deserializer()
Ejemplo n.º 2
0
 def setUp(self):
     self.d = Deserializer()
Ejemplo n.º 3
0
class DeserializerTestCase(unittest.TestCase):
    def setUp(self):
        self.d = Deserializer()

    def test_deserialize_blob(self):
        """Test deserializing a blob."""
        size = b"\x00\x00\x00\x04"
        data = b"\x00\x00\x00\x00"
        remainder = b"\x00\x00\x00\x02"
        self.assertEqual(self.d.deserialize_blob(size + data + remainder), (data, remainder))

    def test_deserialize_bundle(self):
        """Test deserializing a bundle."""
        data = 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"
        self.assertListEqual(self.d.deserialize_bundle(data), ["#bundle", 0.0, ["/test", ",i", 5]])

    def test_deserialize_float32(self):
        """
        Test deserializing the next 4 bytes of a packet as a 32-bit float.

        """
        data = b"A\x00\x00\x00"
        remainder = b"\x00\x00\x00\x02"
        self.assertEqual(self.d.deserialize_float32(data + remainder), (8.0, remainder))

    def test_deserialize_float32_invalid_size(self):
        """
        Test deserializing the next 4 bytes of an invalid packet as a 32-bit
        float.

        """
        self.assertRaises(ValueError, self.d.deserialize_float32, b"")

    def test_deserialize_int32(self):
        """
        Test deserializing the next 4 bytes of a packet as a 32-bit integer.

        """
        data = b"\x00\x00\x00\x04"
        remainder = b"\x00\x00\x00\x02"
        self.assertEqual(self.d.deserialize_int32(data + remainder), (4, remainder))

    def test_deserialize_int32_invalid_size(self):
        """
        Test deserializing the next 4 bytes of an invalid packet as a 32-bit
        integer.

        """
        self.assertRaises(ValueError, self.d.deserialize_int32, b"")

        # def test_deserialize_message(self):
        """Test deserializing a packet into a message."""
        data = b"/test\x00\x00\x00,i\x00\x00\x00\x00\x00\x05"
        self.assertListEqual(self.d.deserialize_message(data), ["/test", ",i", 5])

        # def test_deserialize_message_invalid_typetag(self):
        """
        Test deserializing a packet into a message when a comma is missing
        in the typetag.

        """
        data = b"/test\x00\x00\x00i\x00\x00\x00\x00\x00\x00\x05"
        self.assertRaises(ValueError, self.d.deserialize_message, data)

    def test_deserialize_string(self):
        """Test deserializing a string."""
        data = b"test\x00\x00\x00\x00"
        remainder = b"\x00\x00\x00\x02"
        self.assertEqual(self.d.deserialize_string(data + remainder), ("test", remainder))

    def test_deserialize_timetag_immediate(self):
        """
        Test deserializing the next 8 bytes of a packet as a timetag when it is
        specified to be resolved immediately.

        """
        data = b"\x00\x00\x00\x00\x00\x00\x00\x01"
        remainder = b"\x00\x00\x00\x02"
        self.assertEqual(self.d.deserialize_timetag(data + remainder), (0.0, remainder))
Ejemplo n.º 4
0
class DeserializerTestCase(unittest.TestCase):
    def setUp(self):
        self.d = Deserializer()

    def test_deserialize_blob(self):
        """Test deserializing a blob."""
        size = b'\x00\x00\x00\x04'
        data = b'\x00\x00\x00\x00'
        remainder = b'\x00\x00\x00\x02'
        self.assertEqual(self.d.deserialize_blob(size + data + remainder),
                         (data, remainder))

    def test_deserialize_bundle(self):
        """Test deserializing a bundle."""
        data = 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'
        self.assertListEqual(self.d.deserialize_bundle(data),
                             ['#bundle', 0.0, ['/test', ',i', 5]])

    def test_deserialize_float32(self):
        """
        Test deserializing the next 4 bytes of a packet as a 32-bit float.

        """
        data = b'A\x00\x00\x00'
        remainder = b'\x00\x00\x00\x02'
        self.assertEqual(self.d.deserialize_float32(data + remainder),
                         (8.0, remainder))

    def test_deserialize_float32_invalid_size(self):
        """
        Test deserializing the next 4 bytes of an invalid packet as a 32-bit
        float.

        """
        self.assertRaises(ValueError, self.d.deserialize_float32, b'')

    def test_deserialize_int32(self):
        """
        Test deserializing the next 4 bytes of a packet as a 32-bit integer.

        """
        data = b'\x00\x00\x00\x04'
        remainder = b'\x00\x00\x00\x02'
        self.assertEqual(self.d.deserialize_int32(data + remainder),
                         (4, remainder))

    def test_deserialize_int32_invalid_size(self):
        """
        Test deserializing the next 4 bytes of an invalid packet as a 32-bit
        integer.

        """
        self.assertRaises(ValueError, self.d.deserialize_int32, b'')

        #def test_deserialize_message(self):
        """Test deserializing a packet into a message."""
        data = b'/test\x00\x00\x00,i\x00\x00\x00\x00\x00\x05'
        self.assertListEqual(self.d.deserialize_message(data),
                             ['/test', ',i', 5])

        #def test_deserialize_message_invalid_typetag(self):
        """
        Test deserializing a packet into a message when a comma is missing
        in the typetag.

        """
        data = b'/test\x00\x00\x00i\x00\x00\x00\x00\x00\x00\x05'
        self.assertRaises(ValueError, self.d.deserialize_message, data)

    def test_deserialize_string(self):
        """Test deserializing a string."""
        data = b'test\x00\x00\x00\x00'
        remainder = b'\x00\x00\x00\x02'
        self.assertEqual(self.d.deserialize_string(data + remainder),
                         ('test', remainder))

    def test_deserialize_timetag_immediate(self):
        """
        Test deserializing the next 8 bytes of a packet as a timetag when it is
        specified to be resolved immediately.

        """
        data = b'\x00\x00\x00\x00\x00\x00\x00\x01'
        remainder = b'\x00\x00\x00\x02'
        self.assertEqual(self.d.deserialize_timetag(data + remainder),
                         (0.0, remainder))