From 981bea4f0504a46dbbeaad37ce084343ad84518f Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Thu, 28 Mar 2024 06:36:39 +0100 Subject: [PATCH] Add a test for /dev/stdin --- tests/test_xopen.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/test_xopen.py b/tests/test_xopen.py index 47974a1..1bc94ea 100644 --- a/tests/test_xopen.py +++ b/tests/test_xopen.py @@ -690,3 +690,21 @@ def test_xopen_write_to_pipe(threads, ext): process.wait() process.stdout.close() assert data == CONTENT + + +@pytest.mark.skipif( + not os.path.exists("/dev/stdin"), reason="/dev/stdin does not exist" +) +@pytest.mark.parametrize("threads", (0, 1)) +def test_xopen_dev_stdin_read(threads, ext): + if ext == ".zst" and zstandard is None: + return + file = str(Path(__file__).parent / f"file.txt{ext}") + result = subprocess.run( + f"cat {file} | python -c 'import xopen; " + f'f=xopen.xopen("/dev/stdin", "rt");print(f.read())\'', + shell=True, + stdout=subprocess.PIPE, + encoding="ascii", + ) + assert result.stdout == CONTENT + "\n"