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

Method test_ref_reuse

Lib/test/test_weakref.py:269–290  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

267 "ref2 should be dead after deleting object reference")
268
269 def test_ref_reuse(self):
270 o = C()
271 ref1 = weakref.ref(o)
272 # create a proxy to make sure that there's an intervening creation
273 # between these two; it should make no difference
274 proxy = weakref.proxy(o)
275 ref2 = weakref.ref(o)
276 self.assertIs(ref1, ref2,
277 "reference object w/out callback should be re-used")
278
279 o = C()
280 proxy = weakref.proxy(o)
281 ref1 = weakref.ref(o)
282 ref2 = weakref.ref(o)
283 self.assertIs(ref1, ref2,
284 "reference object w/out callback should be re-used")
285 self.assertEqual(weakref.getweakrefcount(o), 2,
286 "wrong weak ref count for object")
287 del proxy
288 gc_collect() # For PyPy or other GCs.
289 self.assertEqual(weakref.getweakrefcount(o), 1,
290 "wrong weak ref count for object after deleting proxy")
291
292 def test_proxy_reuse(self):
293 o = C()

Callers

nothing calls this directly

Calls 5

gc_collectFunction · 0.90
proxyMethod · 0.80
CClass · 0.70
assertIsMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected