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

Method test_garbage_collection

Lib/test/test_io/test_general.py:502–519  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

500 self.assertEqual(file.buffer.raw.closefd, False)
501
502 def test_garbage_collection(self):
503 # FileIO objects are collected, and collecting them flushes
504 # all data to disk.
505 #
506 # Note that using warnings_helper.check_warnings() will keep the
507 # file alive due to the `source` argument to warn(). So, use
508 # catch_warnings() instead.
509 with warnings.catch_warnings():
510 warnings.simplefilter("ignore", ResourceWarning)
511 f = self.FileIO(os_helper.TESTFN, "wb")
512 f.write(b"abcxxx")
513 f.f = f
514 wr = weakref.ref(f)
515 del f
516 support.gc_collect()
517 self.assertIsNone(wr(), wr)
518 with self.open(os_helper.TESTFN, "rb") as f:
519 self.assertEqual(f.read(), b"abcxxx")
520
521 def test_unbounded_file(self):
522 # Issue #1174606: reading from an unbounded stream such as /dev/zero.

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected