Skip to content

Commit

Permalink
Good test for bytesio
Browse files Browse the repository at this point in the history
  • Loading branch information
rhpvorderman committed Mar 11, 2024
1 parent 840e53f commit 341969d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tests/test_xopen.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,17 +591,20 @@ def test_pass_file_object_for_writing(tmp_path, ext):
assert fh.readline() == first_line


@pytest.mark.parametrize("ext", extensions)
def test_pass_bytesio_for_writing(ext):
@pytest.mark.parametrize(["threads", "ext"], itertools.product((0, 1), extensions))
def test_pass_bytesio_for_reading_and_writing(ext, threads):
filelike = io.BytesIO()
format = ext[1:]
if ext == "":
format = None
if ext == ".zst" and zstandard is None:
return
first_line = CONTENT_LINES[0].encode("utf-8")
with xopen(filelike, "wb", format=format) as f:
f.write(first_line)
writer = xopen(filelike, "wb", format=format, threads=threads)
writer.write(first_line)
if writer is not filelike:
writer.close()
assert not filelike.closed
filelike.seek(0)
with xopen(filelike, "rb", format=format) as fh:
with xopen(filelike, "rb", format=format, threads=threads) as fh:
assert fh.readline() == first_line

0 comments on commit 341969d

Please sign in to comment.