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

Method test_destructor

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

Source from the content-addressed store, hash-verified

381 self.assertGreater(f.tell(), 0)
382
383 def test_destructor(self):
384 record = []
385 class MyFileIO(self.FileIO):
386 def __del__(self):
387 record.append(1)
388 try:
389 f = super().__del__
390 except AttributeError:
391 pass
392 else:
393 f()
394 def close(self):
395 record.append(2)
396 super().close()
397 def flush(self):
398 record.append(3)
399 super().flush()
400 with warnings_helper.check_warnings(('', ResourceWarning)):
401 f = MyFileIO(os_helper.TESTFN, "wb")
402 f.write(b"xxx")
403 del f
404 support.gc_collect()
405 self.assertEqual(record, [1, 2, 3])
406 with self.open(os_helper.TESTFN, "rb") as f:
407 self.assertEqual(f.read(), b"xxx")
408
409 def _check_base_destructor(self, base):
410 record = []

Callers

nothing calls this directly

Calls 5

MyFileIOClass · 0.70
writeMethod · 0.45
assertEqualMethod · 0.45
openMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected