MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_destructor

Method test_destructor

Lib/test/test_io.py:688–712  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

686 self.assertGreater(f.tell(), 0)
687
688 def test_destructor(self):
689 record = []
690 class MyFileIO(self.FileIO):
691 def __del__(self):
692 record.append(1)
693 try:
694 f = super().__del__
695 except AttributeError:
696 pass
697 else:
698 f()
699 def close(self):
700 record.append(2)
701 super().close()
702 def flush(self):
703 record.append(3)
704 super().flush()
705 with warnings_helper.check_warnings(('', ResourceWarning)):
706 f = MyFileIO(os_helper.TESTFN, "wb")
707 f.write(b"xxx")
708 del f
709 support.gc_collect()
710 self.assertEqual(record, [1, 2, 3])
711 with self.open(os_helper.TESTFN, "rb") as f:
712 self.assertEqual(f.read(), b"xxx")
713
714 def _check_base_destructor(self, base):
715 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