diff --git a/test/test_util_pipe.py b/test/test_util_pipe.py index 6aa88f7dd..7f6614a1e 100644 --- a/test/test_util_pipe.py +++ b/test/test_util_pipe.py @@ -30,20 +30,22 @@ from picard.util import pipe def pipe_listener(pipe_handler, end_of_sequence): + IGNORED_OUTPUT = {pipe.Pipe.MESSAGE_TO_IGNORE, pipe.Pipe.NO_RESPONSE_MESSAGE, "", end_of_sequence} received = [] messages = [] + while end_of_sequence not in messages: messages = pipe_handler.read_from_pipe() for message in messages: - if message not in (pipe.Pipe.MESSAGE_TO_IGNORE, pipe.Pipe.NO_RESPONSE_MESSAGE, "", end_of_sequence): + if message not in IGNORED_OUTPUT: received.append(message) - return received + return tuple(received) def pipe_writer(pipe_handler, to_send, end_of_sequence): - for m in to_send: - while not pipe_handler.send_to_pipe(m): + for message in to_send: + while not pipe_handler.send_to_pipe(message): pass while not pipe_handler.send_to_pipe(end_of_sequence): pass @@ -66,16 +68,15 @@ class TestPipe(PicardTestCase): def test_pipe_protocol(self): END_OF_SEQUENCE = "stop" - to_send = [["it", "tests", "picard", "pipe"], - ["test", "number", "two"], - ["my_music_file.mp3"]] - NUM_OF_TESTS = len(to_send) + to_send = (("it", "tests", "picard", "pipe"), + ("test", "number", "two"), + ("my_music_file.mp3",)) pipe_listener_handler = pipe.Pipe(PICARD_APP_NAME, PICARD_FANCY_VERSION_STR) pipe_writer_handler = pipe.Pipe(PICARD_APP_NAME, PICARD_FANCY_VERSION_STR) - for i in range(NUM_OF_TESTS): + for messages in to_send: __pool = concurrent.futures.ThreadPoolExecutor() plistener = __pool.submit(pipe_listener, pipe_listener_handler, END_OF_SEQUENCE) - __pool.submit(pipe_writer, pipe_writer_handler, to_send[i], END_OF_SEQUENCE) - self.assertEqual(plistener.result(), to_send[i]) + __pool.submit(pipe_writer, pipe_writer_handler, messages, END_OF_SEQUENCE) + self.assertEqual(plistener.result(), messages)