diff --git a/test/test_tailpipe.py b/test/test_tailpipe.py index 1f363ccc..0f082091 100644 --- a/test/test_tailpipe.py +++ b/test/test_tailpipe.py @@ -6,7 +6,8 @@ from utils import MockStream from duct import TailPipe -FIXTURE_LIST = [f"ten_{i}" for i in range(1, 7)] +# 10^7 line fixture is about 70MB +FIXTURE_LIST = [f"ten_{i}" for i in range(1, 8)] @pytest.fixture(scope="module", params=FIXTURE_LIST) @@ -14,11 +15,11 @@ def fixture_path(request, tmp_path_factory): num_lines_exponent = int(request.param.split("_")[1]) base_temp_dir = tmp_path_factory.mktemp("fixture_data") file_path = base_temp_dir / f"{request.param}.txt" - print(f"Creating fixture for {num_lines_exponent}") - print(f"10 ^ {num_lines_exponent}: {10 ** num_lines_exponent}") with open(file_path, "w") as f: for i in range(10**num_lines_exponent): f.write(f"{i}\n") + # print(f"10 ^ {num_lines_exponent}: {10 ** num_lines_exponent}") + # print(f"Fixture file size: {os.path.getsize(file_path)} bytes") yield str(file_path) os.remove(file_path) @@ -26,7 +27,7 @@ def fixture_path(request, tmp_path_factory): @pytest.mark.parametrize("fixture_path", FIXTURE_LIST, indirect=True) @patch("sys.stdout", new_callable=lambda: MockStream()) -def test_high_throughput(mock_stdout, fixture_path): +def test_high_throughput_stdout(mock_stdout, fixture_path): with tempfile.NamedTemporaryFile(mode="wb") as tmpfile: process = subprocess.Popen( ["cat", fixture_path], @@ -43,6 +44,26 @@ def test_high_throughput(mock_stdout, fixture_path): assert mock_stdout.getvalue() == expected +@pytest.mark.parametrize("fixture_path", FIXTURE_LIST, indirect=True) +@patch("sys.stderr", new_callable=lambda: MockStream()) +def test_high_throughput_stderr(mock_stderr, fixture_path): + with tempfile.NamedTemporaryFile(mode="wb") as tmpfile: + process = subprocess.Popen( + ["./test/cat_to_err.py", fixture_path], + stdout=subprocess.DEVNULL, + stderr=tmpfile, + ) + stream = TailPipe(tmpfile.name, mock_stderr.buffer) + stream.start() + process.wait() + stream.close() + + assert process.returncode == 0 + with open(fixture_path, "rb") as fixture: + expected = fixture.read() + assert mock_stderr.getvalue() == expected + + @patch("sys.stdout", new_callable=lambda: MockStream()) def test_close(mock_stdout): with tempfile.NamedTemporaryFile(mode="wb") as tmpfile: @@ -50,7 +71,3 @@ def test_close(mock_stdout): stream.start() stream.close() assert stream.infile.closed - - -if __name__ == "__main__": - test_high_throughput() diff --git a/tox.ini b/tox.ini index d2d7530c..d74292de 100644 --- a/tox.ini +++ b/tox.ini @@ -33,7 +33,6 @@ commands = mypy src test [pytest] -addopts = --cov=duct --no-cov-on-fail filterwarnings = error norecursedirs = test/data markers =