def test_parse_partial_msgs(self):
        """
        Tests that Pickle message parser accepts partial messages.
        """
        parser = PickleMessageParser()

        msg = b''.join([
            b"I35\n.(dp0\nS'msg'\np1\nS'hello world'\np2\ns.",
            b"I19\n.(dp0\nS'x'\np1\nI42\ns.",
        ])

        chunk_size = 8

        actual_messages = []
        for pos in range(0, len(msg), chunk_size):
            parser.push(msg[pos:pos+chunk_size])
            for parsed_message in parser.messages():
                actual_messages.append(parsed_message)

        self.assertEquals([{'msg': 'hello world'}, {'x': 42}], actual_messages)
    def test_parse_messages(self):
        """
        Tests Pickle message parser.
        """
        parser = PickleMessageParser()

        msg1 = b"I35\n.(dp0\nS'msg'\np1\nS'hello world'\np2\ns."
        msg2 = b"I19\n.(dp0\nS'x'\np1\nI42\ns."

        parser.push(msg1)
        self.assertEquals([{'msg': 'hello world'}], list(parser.messages()))

        parser.push(msg2)
        self.assertEquals([{'x': 42}], list(parser.messages()))