From 024204e439e429a58ea853e8bbcda3475ae70179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 17 Apr 2019 14:10:47 +0200 Subject: [PATCH] Make PipeIOServer API more consistent with clients --- echo_server.py | 2 +- pipe_io_server/pipe_io_server.py | 2 +- tests.py | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/echo_server.py b/echo_server.py index 2ea4c2b..12ef8b2 100644 --- a/echo_server.py +++ b/echo_server.py @@ -5,7 +5,7 @@ from pipe_io_server import PipeIOServer class EchoPipeIOServer(PipeIOServer): def handle_message(self, message): - self.send(message) + self.send_message(message) if __name__ == "__main__": diff --git a/pipe_io_server/pipe_io_server.py b/pipe_io_server/pipe_io_server.py index de8d088..632d92a 100644 --- a/pipe_io_server/pipe_io_server.py +++ b/pipe_io_server/pipe_io_server.py @@ -37,7 +37,7 @@ class PipeIOServer(ABC, Thread): def handle_message(self, message): raise NotImplementedError() - def send(self, message): + def send_message(self, message): self._writer_thread.write(message) @terminate_process_on_failure diff --git a/tests.py b/tests.py index 16bd122..99321bd 100644 --- a/tests.py +++ b/tests.py @@ -63,7 +63,7 @@ class IOPipes: self.in_pipe.close() self.out_pipe.close() - def send(self, message): + def send_message(self, message): self.in_pipe.write(message + b'\n') self.in_pipe.flush() @@ -116,7 +116,7 @@ def test_out_pipe_closed_stop(): ] ) def test_io(io_pipes, test_data): - io_pipes.send(test_data.encode()) + io_pipes.send_message(test_data.encode()) assert io_pipes.recv().decode() == test_data @@ -133,7 +133,7 @@ def test_io(io_pipes, test_data): ) def test_io_large_data(io_pipes, test_data_size): test_data = urandom(test_data_size).replace(b'\n', b'') - io_pipes.send(test_data) + io_pipes.send_message(test_data) received_data = io_pipes.recv() assert received_data == test_data @@ -141,13 +141,13 @@ def test_io_large_data(io_pipes, test_data_size): def test_io_stress(io_pipes): for _ in range(2222): test_data = urandom(randint(1, 1024)).replace(b'\n', b'') - io_pipes.send(test_data) + io_pipes.send_message(test_data) assert io_pipes.recv() == test_data def test_io_newlines(io_pipes): times = randint(1, 512) - io_pipes.send(b'\n' * times) + io_pipes.send_message(b'\n' * times) for _ in range(times + 1): # IOPipes.send appends +1 assert io_pipes.recv() == b'' @@ -169,5 +169,5 @@ def test_json_io(io_pipes): f'{token_urlsafe(8)}': [token_urlsafe(4) for i in range(10)], } } - io_pipes.send(dumps(test_data).encode()) + io_pipes.send_message(dumps(test_data).encode()) assert loads(io_pipes.recv()) == test_data