From b7bc79528945a9c45d4a947532a463c6fd1f852f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Sun, 16 Dec 2018 22:49:23 +0100 Subject: [PATCH] Implement test case for large data --- tests.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/tests.py b/tests.py index 50babce..90a3cf8 100644 --- a/tests.py +++ b/tests.py @@ -1,5 +1,5 @@ # pylint: disable=redefined-outer-name -from os import stat +from os import stat, urandom from os.path import exists, dirname, realpath, join from stat import S_ISFIFO from secrets import token_urlsafe @@ -43,9 +43,26 @@ def test_pipes_isfifo(pipe_io): token_urlsafe(32) ] ) -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 +def test_io(pipe_io, test_data): + File(pipe_io.in_pipe, string=True).write(test_data) + assert File(pipe_io.out_pipe, string=True).read() == test_data + + +@pytest.mark.parametrize( + 'test_data_size', [ + 1024, + 1024*1024, + 2*1024*1024, + 4*1024*1024, + 8*1024*1024, + 16*1024*1024, + 32*1024*1024 + ] +) +def test_io_large_data(pipe_io, test_data_size): + random_data = urandom(test_data_size) + File(pipe_io.in_pipe).write(random_data) + assert File(pipe_io.out_pipe).read() == random_data def test_stop_removes_pipes(pipe_io): @@ -55,13 +72,14 @@ def test_stop_removes_pipes(pipe_io): class File: - def __init__(self, path): + def __init__(self, path, string=False): self.path = path + self._filemode = '' if string else 'b' def write(self, what): - with open(self.path, 'w') as ofile: + with open(self.path, f'w{self._filemode}') as ofile: ofile.write(what) def read(self): - with open(self.path, 'r') as ifile: + with open(self.path, f'r{self._filemode}') as ifile: return ifile.read()