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

Method test_callback_when_method_dead

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

Source from the content-addressed store, hash-verified

1225 self.assertEqual(calls, [r])
1226
1227 def test_callback_when_method_dead(self):
1228 # Test callback behaviour when method dies first.
1229 C = self._subclass()
1230 calls = []
1231 def cb(arg):
1232 calls.append(arg)
1233 o = C(1)
1234 r = weakref.WeakMethod(o.some_method, cb)
1235 del C.some_method
1236 gc.collect()
1237 self.assertEqual(calls, [r])
1238 # Callback is only called once.
1239 del o
1240 gc.collect()
1241 self.assertEqual(calls, [r])
1242
1243 @support.cpython_only
1244 def test_no_cycles(self):

Callers

nothing calls this directly

Calls 4

_subclassMethod · 0.95
CClass · 0.70
collectMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected