Skip to content

Commit b3dd998

Browse files
committed
Add test for BytesIO objects
1 parent 865cb98 commit b3dd998

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/test_xopen.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,3 +588,17 @@ def test_pass_file_object_for_writing(tmp_path, ext):
588588
f.write(first_line)
589589
with xopen(tmp_path / "out{ext}", "rb") as fh:
590590
assert fh.readline() == first_line
591+
592+
593+
@pytest.mark.parametrize("ext", extensions)
594+
def test_pass_bytesio_for_writing(ext):
595+
filelike = io.BytesIO()
596+
format = ext[1:]
597+
if ext == ".zst" and zstandard is None:
598+
return
599+
first_line = CONTENT_LINES[0].encode("utf-8")
600+
with xopen(filelike, "wb", format=format) as f:
601+
f.write(first_line)
602+
filelike.seek(0)
603+
with xopen(filelike, "rb", format=format) as fh:
604+
assert fh.readline() == first_line

0 commit comments

Comments
 (0)