MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_all_freed

Method test_all_freed

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

Source from the content-addressed store, hash-verified

2203 self.assertEqual(res, expected)
2204
2205 def test_all_freed(self):
2206 # we want a weakrefable subclass of weakref.finalize
2207 class MyFinalizer(weakref.finalize):
2208 pass
2209
2210 a = self.A()
2211 res = []
2212 def callback():
2213 res.append(123)
2214 f = MyFinalizer(a, callback)
2215
2216 wr_callback = weakref.ref(callback)
2217 wr_f = weakref.ref(f)
2218 del callback, f
2219
2220 self.assertIsNotNone(wr_callback())
2221 self.assertIsNotNone(wr_f())
2222
2223 del a
2224 self._collect_if_necessary()
2225
2226 self.assertIsNone(wr_callback())
2227 self.assertIsNone(wr_f())
2228 self.assertEqual(res, [123])
2229
2230 @classmethod
2231 def run_in_child(cls):

Callers

nothing calls this directly

Calls 6

_collect_if_necessaryMethod · 0.95
MyFinalizerClass · 0.85
AMethod · 0.80
assertIsNotNoneMethod · 0.80
assertIsNoneMethod · 0.80
assertEqualMethod · 0.45

Tested by

no test coverage detected