Skip to content

Commit 3967def

Browse files
committed
Test stdin and stdout
1 parent 63a10ff commit 3967def

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/test_xopen.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
import bz2
55
import sys
6+
import tempfile
67
from contextlib import contextmanager
78
import functools
89
import gzip
@@ -634,3 +635,21 @@ def test_pass_bytesio_for_reading_and_writing(ext, threads):
634635
filelike.seek(0)
635636
with xopen(filelike, "rb", format=format, threads=threads) as fh:
636637
assert fh.readline() == first_line
638+
639+
640+
def test_xopen_stdin(monkeypatch):
641+
with open(TEST_DIR / "file.txt") as in_file:
642+
monkeypatch.setattr("sys.stdin", in_file)
643+
with xopen("-", "rt") as f:
644+
data = f.read()
645+
assert data == CONTENT
646+
647+
648+
def test_xopen_stdout(monkeypatch):
649+
with tempfile.TemporaryFile(mode="w+t") as raw:
650+
monkeypatch.setattr("sys.stdout", raw)
651+
with xopen("-", "wt") as f:
652+
f.write("Hello world!")
653+
raw.seek(0)
654+
data = raw.read()
655+
assert data == "Hello world!"

0 commit comments

Comments
 (0)