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

Method test_callback_when_object_dead

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

Source from the content-addressed store, hash-verified

1209 self.assertIs(r(), None)
1210
1211 def test_callback_when_object_dead(self):
1212 # Test callback behaviour when object dies first.
1213 C = self._subclass()
1214 calls = []
1215 def cb(arg):
1216 calls.append(arg)
1217 o = C(1)
1218 r = weakref.WeakMethod(o.some_method, cb)
1219 del o
1220 gc.collect()
1221 self.assertEqual(calls, [r])
1222 # Callback is only called once.
1223 C.some_method = Object.some_method
1224 gc.collect()
1225 self.assertEqual(calls, [r])
1226
1227 def test_callback_when_method_dead(self):
1228 # Test callback behaviour when method dies first.

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