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

Method test_resurrection_is_transitive

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

Source from the content-addressed store, hash-verified

961 gc.enable()
962
963 def test_resurrection_is_transitive(self):
964 class Cargo:
965 def __init__(self):
966 self.me = self
967
968 class Lazarus:
969 resurrected_instances = []
970
971 def __del__(self):
972 Lazarus.resurrected_instances.append(self)
973
974 gc.collect()
975 gc.disable()
976
977 laz = Lazarus()
978 cargo = Cargo()
979 cargo_id = id(cargo)
980
981 # Create a cycle between cargo and laz
982 laz.cargo = cargo
983 cargo.laz = laz
984
985 # Drop the references, force a collection and check that
986 # everything was resurrected.
987 del laz, cargo
988 gc.collect()
989 self.assertEqual(len(Lazarus.resurrected_instances), 1)
990 instance = Lazarus.resurrected_instances.pop()
991 self.assertHasAttr(instance, "cargo")
992 self.assertEqual(id(instance.cargo), cargo_id)
993
994 gc.collect()
995 gc.enable()
996
997 def test_resurrection_does_not_block_cleanup_of_other_objects(self):
998

Callers

nothing calls this directly

Calls 9

LazarusClass · 0.85
CargoClass · 0.85
idFunction · 0.85
assertHasAttrMethod · 0.80
collectMethod · 0.45
disableMethod · 0.45
assertEqualMethod · 0.45
popMethod · 0.45
enableMethod · 0.45

Tested by

no test coverage detected