From 1b69e09276b134cde06c2f2102f5ed13a9390af1 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 7 Dec 2018 23:34:59 +0000 Subject: [PATCH] Restructure app so isort actually runs --- ipc_unix/client.py | 11 ----------- ipc_unix/{server.py => simple.py} | 8 ++++++++ tests/__init__.py | 4 ++-- tests/test_basic.py | 6 ------ tests/{test_server.py => test_simple.py} | 6 +++--- 5 files changed, 13 insertions(+), 22 deletions(-) delete mode 100644 ipc_unix/client.py rename ipc_unix/{server.py => simple.py} (82%) delete mode 100644 tests/test_basic.py rename tests/{test_server.py => test_simple.py} (89%) diff --git a/ipc_unix/client.py b/ipc_unix/client.py deleted file mode 100644 index fc9eaee..0000000 --- a/ipc_unix/client.py +++ /dev/null @@ -1,11 +0,0 @@ -import socket - -import ujson -from ipc_unix.utils import read_payload - - -def send_to(socket_path, data): - with socket.socket(socket.AF_UNIX, type=socket.SOCK_STREAM) as sock: - sock.connect(socket_path) - sock.sendall(ujson.dumps(data).encode() + b"\n") - return read_payload(sock) diff --git a/ipc_unix/server.py b/ipc_unix/simple.py similarity index 82% rename from ipc_unix/server.py rename to ipc_unix/simple.py index 6343988..66afe9f 100644 --- a/ipc_unix/server.py +++ b/ipc_unix/simple.py @@ -1,3 +1,4 @@ +import socket import socketserver import threading @@ -5,6 +6,13 @@ import ujson from ipc_unix.utils import read_payload +def send_to(socket_path, data): + with socket.socket(socket.AF_UNIX, type=socket.SOCK_STREAM) as sock: + sock.connect(socket_path) + sock.sendall(ujson.dumps(data).encode() + b"\n") + return read_payload(sock) + + class RequestHandler(socketserver.BaseRequestHandler): def handle_request(self, request): raise NotImplementedError("Failed to override `handle_request`") diff --git a/tests/__init__.py b/tests/__init__.py index fa15af4..50de12b 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,9 +1,9 @@ -from ipc_unix import server +from ipc_unix.simple import Server import tempfile import os -class EchoServer(server.Server): +class EchoServer(Server): def handle_request(self, request): return request diff --git a/tests/test_basic.py b/tests/test_basic.py deleted file mode 100644 index 9f71b53..0000000 --- a/tests/test_basic.py +++ /dev/null @@ -1,6 +0,0 @@ -from unittest import TestCase - - -class BasicTestCase(TestCase): - def test_something_basic(self): - self.assertTrue(True) diff --git a/tests/test_server.py b/tests/test_simple.py similarity index 89% rename from tests/test_server.py rename to tests/test_simple.py index 53c59a6..740fcb3 100644 --- a/tests/test_server.py +++ b/tests/test_simple.py @@ -1,16 +1,16 @@ from functools import partial from unittest import TestCase -from ipc_unix import client +from ipc_unix.simple import send_to from tests import EchoServer, get_temp_file_path -class BasicServerTestCase(TestCase): +class SimpleServerTestCase(TestCase): def setUp(self): self.socket_path = get_temp_file_path() self.server = EchoServer(self.socket_path) self.server.serve_in_thread() - self.send_to_client = partial(client.send_to, self.socket_path) + self.send_to_client = partial(send_to, self.socket_path) def tearDown(self): self.server.shutdown()