Skip to content

Commit 1bddda6

Browse files
committed
Write a test for proper flushing of the threaded writer
1 parent b0728bb commit 1bddda6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/test_gzip_ng_threaded.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,19 @@ def test_threaded_program_can_exit_on_error(tmp_path, mode, threads):
230230
)
231231
f.write("raise Exception('Error')\n")
232232
subprocess.run([sys.executable, str(program)])
233+
234+
235+
@pytest.mark.parametrize("threads", [1, 2])
236+
def test_flush(tmp_path, threads):
237+
test_file = tmp_path / "output.gz"
238+
with gzip_ng_threaded.open(test_file, "wb", threads=threads) as f:
239+
f.write(b"1")
240+
f.flush()
241+
assert gzip.decompress(test_file.read_bytes()) == b"1"
242+
f.write(b"2")
243+
f.flush()
244+
assert gzip.decompress(test_file.read_bytes()) == b"12"
245+
f.write(b"3")
246+
f.flush()
247+
assert gzip.decompress(test_file.read_bytes()) == b"123"
248+
assert gzip.decompress(test_file.read_bytes()) == b"123"

0 commit comments

Comments
 (0)