MCPcopy Index your code
hub / github.com/python/cpython / test_garbage_collection

Method test_garbage_collection

Lib/test/test_io/test_textio.py:1461–1477  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1459 self.assertRaises(Exception, repr, t)
1460
1461 def test_garbage_collection(self):
1462 # C TextIOWrapper objects are collected, and collecting them flushes
1463 # all data to disk.
1464 # The Python version has __del__, so it ends in gc.garbage instead.
1465 with warnings.catch_warnings():
1466 warnings.simplefilter("ignore", ResourceWarning)
1467 rawio = self.FileIO(os_helper.TESTFN, "wb")
1468 b = self.BufferedWriter(rawio)
1469 t = self.TextIOWrapper(b, encoding="ascii")
1470 t.write("456def")
1471 t.x = t
1472 wr = weakref.ref(t)
1473 del t
1474 support.gc_collect()
1475 self.assertIsNone(wr(), wr)
1476 with self.open(os_helper.TESTFN, "rb") as f:
1477 self.assertEqual(f.read(), b"456def")
1478
1479 def test_rwpair_cleared_before_textio(self):
1480 # Issue 13070: TextIOWrapper's finalization would crash when called

Callers

nothing calls this directly

Calls 5

writeMethod · 0.95
assertIsNoneMethod · 0.80
openMethod · 0.45
assertEqualMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected