def test_corrupted_data_is_bypassed(self): mock_digest = self.mocker.mock() mock_digest(mocker.ANY) self.mocker.result("e5fcf4f4606df6368779205e29b22e5851355de3XXXXX") self.mocker.replay() in_stream = StringIO(self.serialized_message) messages = utils.recv_messages(in_stream, mock_digest) self.assertRaises(StopIteration, lambda: messages.next())
def test_valid_data_is_deserialized(self): mock_digest = self.mocker.mock() mock_digest(mocker.ANY) self.mocker.result("e5fcf4f4606df6368779205e29b22e5851355de3") self.mocker.replay() in_stream = StringIO(self.serialized_message) messages = utils.recv_messages(in_stream, mock_digest) self.assertEqual(messages.next(), "message")
def test_unix_socket_stream_support(self): mock_digest = self.mocker.mock() mock_digest(mocker.ANY) self.mocker.result("e5fcf4f4606df6368779205e29b22e5851355de3") self.mocker.replay() out_stream = utils.get_readable_socket(self.sock_path) in_stream = utils.get_writable_socket(self.sock_path) in_stream.sendall(self.serialized_message) messages = utils.recv_messages(out_stream, mock_digest) self.assertEqual(messages.next(), "message")
def test_socket_stream_support(self): import socket mock_digest = self.mocker.mock() mock_digest(mocker.ANY) self.mocker.result("e5fcf4f4606df6368779205e29b22e5851355de3") self.mocker.replay() in_stream, out_stream = socket.socketpair() in_stream.sendall(self.serialized_message) messages = utils.recv_messages(out_stream, mock_digest) self.assertEqual(messages.next(), "message")
def test_raises_StopIteration_while_the_stream_is_exhausted(self): in_stream = StringIO() messages = utils.recv_messages(in_stream, utils.make_digest) self.assertRaises(StopIteration, lambda: messages.next())