Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: Add test for reference cycle in gzip.GzipFile
  • Loading branch information
Mr-Sunglasses committed Mar 6, 2025
commit 79b7f6ca15d27e1461005213632ddb3aa0fd6704
19 changes: 19 additions & 0 deletions Lib/test/test_gzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,25 @@ def sizes():
self.assertEqual(f.read(100), b'')
self.assertEqual(nread, len(uncompressed))

def test_no_refloop_with_writestream(self):
"""Test that the _WriteBufferStream __del__ method prevents reference loops."""
Comment thread
Mr-Sunglasses marked this conversation as resolved.
Outdated
import gc

gc.collect()

before_count = len(gc.get_objects())

with io.BytesIO() as bio:
with gzip.GzipFile(fileobj=bio, mode="wb") as f:
f.write(b"test data")

gc.collect(0)

# Check that all objects were properly cleaned up
after_count = len(gc.get_objects())
self.assertLess(after_count - before_count, 10,
"Too many objects remain after GzipFile cleanup")

def test_textio_readlines(self):
# Issue #10791: TextIOWrapper.readlines() fails when wrapping GzipFile.
lines = (data1 * 50).decode("ascii").splitlines(keepends=True)
Expand Down