MCPcopy Create free account
hub / github.com/python/cpython / test_resurrection_only_happens_once_per_object

Method test_resurrection_only_happens_once_per_object

Lib/test/test_gc.py:927–961  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

925 self.assertRaises(TypeError, gc.get_objects, 1.234)
926
927 def test_resurrection_only_happens_once_per_object(self):
928 class A: # simple self-loop
929 def __init__(self):
930 self.me = self
931
932 class Lazarus(A):
933 resurrected = 0
934 resurrected_instances = []
935
936 def __del__(self):
937 Lazarus.resurrected += 1
938 Lazarus.resurrected_instances.append(self)
939
940 gc.collect()
941 gc.disable()
942
943 # We start with 0 resurrections
944 laz = Lazarus()
945 self.assertEqual(Lazarus.resurrected, 0)
946
947 # Deleting the instance and triggering a collection
948 # resurrects the object
949 del laz
950 gc.collect()
951 self.assertEqual(Lazarus.resurrected, 1)
952 self.assertEqual(len(Lazarus.resurrected_instances), 1)
953
954 # Clearing the references and forcing a collection
955 # should not resurrect the object again.
956 Lazarus.resurrected_instances.clear()
957 self.assertEqual(Lazarus.resurrected, 1)
958 gc.collect()
959 self.assertEqual(Lazarus.resurrected, 1)
960
961 gc.enable()
962
963 def test_resurrection_is_transitive(self):
964 class Cargo:

Callers

nothing calls this directly

Calls 6

LazarusClass · 0.85
collectMethod · 0.45
disableMethod · 0.45
assertEqualMethod · 0.45
clearMethod · 0.45
enableMethod · 0.45

Tested by

no test coverage detected