def test_unpacking_many(self):
        """
        Test if multiple messages are correctly unpacked
        from a binary string ot an array of objects
        """
        msg = self.get_foo_msg()
        packed = struct.pack("!B", msg.__class__.id) + struct.pack("!B", 2) + \
            struct.pack('!I', 1) + struct.pack('!I', 3)

        msg = self.get_bar_msg()
        string_length = len(bytes(msg['name'], 'utf-8'))
        packed += struct.pack("!B", msg.__class__.id) + \
            struct.pack("!I", string_length) + \
            struct.pack("!{}s".format(string_length), bytes(msg['name'], 'utf-8')) + \
            struct.pack("!H", 42)
        msg = self.get_vector_msg()
        packed += struct.pack("!B", msg.__class__.id) + \
            struct.pack("!f", 1) + \
            struct.pack("!f", 7.77)

        unpacked = unpack_messages(packed, self.factory)
        self.assertEqual(unpacked[0].__class__.__name__, 'FooMessage')
        self.assertEqual(unpacked[1].__class__.__name__, 'BarMessage')
        self.assertEqual(unpacked[2].__class__.__name__, 'VectorMessage')

        self.assertEqual(unpacked[0]['direction'], 'south')
        self.assertEqual(unpacked[0]['x'], 1)
        self.assertEqual(unpacked[0]['y'], 3)

        self.assertEqual(unpacked[1]['name'], u'Yoda')
        self.assertEqual(unpacked[1]['score'], 42)

        self.assertEqual(unpacked[2]['x'], 1)
        self.assertAlmostEqual(unpacked[2]['y'], 7.77, places=2)
    def test_unpacking_many(self):
        """
        Test if multiple messages are correctly unpacked
        from a binary string ot an array of objects
        """
        msg = self.get_foo_msg()
        packed = (
            struct.pack("!B", msg.__class__.id) + struct.pack("!B", 2) + struct.pack("!I", 1) + struct.pack("!I", 3)
        )

        msg = self.get_bar_msg()
        string_length = len(bytes(msg["name"], "utf-8"))
        packed += (
            struct.pack("!B", msg.__class__.id)
            + struct.pack("!I", string_length)
            + struct.pack("!{}s".format(string_length), bytes(msg["name"], "utf-8"))
            + struct.pack("!H", 42)
        )
        msg = self.get_vector_msg()
        packed += struct.pack("!B", msg.__class__.id) + struct.pack("!f", 1) + struct.pack("!f", 7.77)

        unpacked = unpack_messages(packed, self.factory)
        self.assertEqual(unpacked[0].__class__.__name__, "FooMessage")
        self.assertEqual(unpacked[1].__class__.__name__, "BarMessage")
        self.assertEqual(unpacked[2].__class__.__name__, "VectorMessage")

        self.assertEqual(unpacked[0]["direction"], "south")
        self.assertEqual(unpacked[0]["x"], 1)
        self.assertEqual(unpacked[0]["y"], 3)

        self.assertEqual(unpacked[1]["name"], u"Yoda")
        self.assertEqual(unpacked[1]["score"], 42)

        self.assertEqual(unpacked[2]["x"], 1)
        self.assertAlmostEqual(unpacked[2]["y"], 7.77, places=2)
    def test_unpacking_many_of_one_type(self):
        """
        Test if multiple messages of one kind are correctly unpacked
        from a binary string ot an array of objects
        """

        packed = b''

        for n in range(10):
            msg = self.get_foo_msg()
            packed += struct.pack("!B", msg.__class__.id) + struct.pack("!B", 2) + \
                struct.pack('!I', 1) + struct.pack('!I', 3)

        unpacked = unpack_messages(packed, self.factory)
        self.assertEqual(unpacked[0].__class__.__name__, 'FooMessage')
        self.assertEqual(unpacked[1].__class__.__name__, 'FooMessage')

        self.assertEqual(unpacked[0]['direction'], 'south')
        self.assertEqual(unpacked[0]['x'], 1)
        self.assertEqual(unpacked[0]['y'], 3)
    def test_unpacking_many_of_one_type(self):
        """
        Test if multiple messages of one kind are correctly unpacked
        from a binary string ot an array of objects
        """

        packed = b""

        for n in range(10):
            msg = self.get_foo_msg()
            packed += (
                struct.pack("!B", msg.__class__.id) + struct.pack("!B", 2) + struct.pack("!I", 1) + struct.pack("!I", 3)
            )

        unpacked = unpack_messages(packed, self.factory)
        self.assertEqual(unpacked[0].__class__.__name__, "FooMessage")
        self.assertEqual(unpacked[1].__class__.__name__, "FooMessage")

        self.assertEqual(unpacked[0]["direction"], "south")
        self.assertEqual(unpacked[0]["x"], 1)
        self.assertEqual(unpacked[0]["y"], 3)