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

Method test_weakrefs

Lib/test/test_descr.py:2392–2421  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2390 self.assertNotIn(10, p10)
2391
2392 def test_weakrefs(self):
2393 # Testing weak references...
2394 import weakref
2395 class C(object):
2396 pass
2397 c = C()
2398 r = weakref.ref(c)
2399 self.assertEqual(r(), c)
2400 del c
2401 support.gc_collect()
2402 self.assertEqual(r(), None)
2403 del r
2404 class NoWeak(object):
2405 __slots__ = ['foo']
2406 no = NoWeak()
2407 try:
2408 weakref.ref(no)
2409 except TypeError as msg:
2410 self.assertIn("weak reference", str(msg))
2411 else:
2412 self.fail("weakref.ref(no) should be illegal")
2413 class Weak(object):
2414 __slots__ = ['foo', '__weakref__']
2415 yes = Weak()
2416 r = weakref.ref(yes)
2417 self.assertEqual(r(), yes)
2418 del yes
2419 support.gc_collect()
2420 self.assertEqual(r(), None)
2421 del r
2422
2423 def test_properties(self):
2424 # Testing property...

Callers

nothing calls this directly

Calls 8

NoWeakClass · 0.85
strFunction · 0.85
assertInMethod · 0.80
CClass · 0.70
WeakClass · 0.70
rFunction · 0.50
assertEqualMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected