From a8d73483cfe9d5482b8948f8b2d196c60fb2c25a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 14 Dec 2018 15:40:11 +0100 Subject: [PATCH] Implement basic test cases --- tests.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests.py diff --git a/tests.py b/tests.py new file mode 100644 index 0000000..73398b9 --- /dev/null +++ b/tests.py @@ -0,0 +1,52 @@ +from os import stat +from os.path import exists +from stat import S_ISFIFO + +import pytest + +from echo_server import EchoPipeIOServer + + +@pytest.fixture +def pipe_io(): + pipe_server = EchoPipeIOServer() + pipe_server.run() + yield pipe_server + pipe_server.stop() + + +def test_pipes_exist(pipe_io): + for path in (pipe_io.in_pipe, pipe_io.out_pipe): + assert exists(path) + + +def test_pipes_isfifo(pipe_io): + for path in (pipe_io.in_pipe, pipe_io.out_pipe): + assert S_ISFIFO(stat(path).st_mode) + + +@pytest.mark.parametrize( + 'test_data', [ + 'cats', + 'cheese', + 'You ever wonder why we are here?', + 'Lorem ipsum dolor sit amet', + 'You always have a plan, Dutch!' + ] +) +def test_echo_server(pipe_io, test_data): + File(pipe_io.in_pipe).write(test_data) + assert File(pipe_io.out_pipe).read() == test_data + + +class File: + def __init__(self, path): + self.path = path + + def write(self, what): + with open(self.path, 'w') as ofile: + ofile.write(what) + + def read(self): + with open(self.path, 'r') as ifile: + return ifile.read()