Skip to content

Commit df45eaf

Browse files
committed
Reproduce error where program with error does not close.
Fix linting
1 parent 12b0703 commit df45eaf

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/test_gzip_ng_threaded.py

+21
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import io
1010
import itertools
1111
import os
12+
import subprocess
13+
import sys
1214
import tempfile
1315
from pathlib import Path
1416

@@ -209,3 +211,22 @@ def test_threaded_writer_does_not_close_stream():
209211
assert not test_stream.closed
210212
test_stream.seek(0)
211213
assert gzip.decompress(test_stream.read()) == b"thisisatest"
214+
215+
216+
@pytest.mark.timeout(5)
217+
@pytest.mark.parametrize(
218+
["mode", "threads"], itertools.product(["rb", "wb"], [1, 2]))
219+
def test_threaded_program_can_exit_on_error(tmp_path, mode, threads):
220+
program = tmp_path / "no_context_manager.py"
221+
test_file = tmp_path / "output.gz"
222+
# Write 40 mb input data to saturate read buffer. Because of the repetitive
223+
# nature the resulting gzip file is very small (~40 KiB).
224+
test_file.write_bytes(gzip.compress(b"test" * (10 * 1024 * 1024)))
225+
with open(program, "wt") as f:
226+
f.write("from zlib_ng import gzip_ng_threaded\n")
227+
f.write(
228+
f"f = gzip_ng_threaded.open('{test_file}', "
229+
f"mode='{mode}', threads={threads})\n"
230+
)
231+
f.write("raise Exception('Error')\n")
232+
subprocess.run([sys.executable, str(program)])

0 commit comments

Comments
 (0)