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

Method test_legacy_finalizer_newclass

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

Source from the content-addressed store, hash-verified

201
202 @cpython_only
203 def test_legacy_finalizer_newclass(self):
204 # A() is uncollectable if it is part of a cycle, make sure it shows up
205 # in gc.garbage.
206 @with_tp_del
207 class A(object):
208 def __tp_del__(self): pass
209 class B(object):
210 pass
211 a = A()
212 a.a = a
213 id_a = id(a)
214 b = B()
215 b.b = b
216 gc.collect()
217 del a
218 del b
219 self.assertNotEqual(gc.collect(), 0)
220 for obj in gc.garbage:
221 if id(obj) == id_a:
222 del obj.a
223 break
224 else:
225 self.fail("didn't find obj in garbage (finalizer)")
226 gc.garbage.remove(obj)
227
228 def test_function(self):
229 # Tricky: f -> d -> f, code should call d.clear() after the exec to

Callers

nothing calls this directly

Calls 7

idFunction · 0.85
assertNotEqualMethod · 0.80
AClass · 0.70
BClass · 0.70
collectMethod · 0.45
failMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected