Skip to content

Commit e94b965

Browse files
committed
Add further tests for threaded open
1 parent 0c32664 commit e94b965

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

tests/test_igzip_threaded.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ def test_threaded_read():
2525
assert thread_data == data
2626

2727

28-
def test_threaded_write():
28+
@pytest.mark.parametrize("mode", ["wb", "wt"])
29+
def test_threaded_write(mode):
2930
with tempfile.NamedTemporaryFile("wb", delete=False) as tmp:
30-
with igzip_threaded.open(tmp, "wb", threads=3) as out_file:
31-
with gzip.open(TEST_FILE) as in_file:
31+
with igzip_threaded.open(tmp, mode, threads=3) as out_file:
32+
with gzip.open(TEST_FILE, "rb" if "b" in mode else "rt") as in_file:
3233
while True:
3334
block = in_file.read(128 * 1024)
3435
if not block:
@@ -41,6 +42,22 @@ def test_threaded_write():
4142
assert test_data == out_data
4243

4344

45+
def test_threaded_open_no_threads():
46+
with tempfile.TemporaryFile("rb") as tmp:
47+
klass = igzip_threaded.open(tmp, "rb", threads=0)
48+
# igzip.IGzipFile inherits gzip.Gzipfile
49+
assert isinstance(klass, gzip.GzipFile)
50+
51+
52+
def test_threaded_open_not_a_file_or_pathlike():
53+
i_am_a_tuple = (1, 2, 3)
54+
with pytest.raises(TypeError) as error:
55+
igzip_threaded.open(i_am_a_tuple)
56+
error.match("str")
57+
error.match("bytes")
58+
error.match("file")
59+
60+
4461
# Test whether threaded readers and writers throw an error rather than hang
4562
# indefinitely.
4663

0 commit comments

Comments
 (0)