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

Method test_resurrection_is_transitive

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected