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

Method test_order

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

Source from the content-addressed store, hash-verified

2164 self.assertRaises(TypeError, weakref.finalize)
2165
2166 def test_order(self):
2167 a = self.A()
2168 res = []
2169
2170 f1 = weakref.finalize(a, res.append, 'f1')
2171 f2 = weakref.finalize(a, res.append, 'f2')
2172 f3 = weakref.finalize(a, res.append, 'f3')
2173 f4 = weakref.finalize(a, res.append, 'f4')
2174 f5 = weakref.finalize(a, res.append, 'f5')
2175
2176 # make sure finalizers can keep themselves alive
2177 del f1, f4
2178
2179 self.assertTrue(f2.alive)
2180 self.assertTrue(f3.alive)
2181 self.assertTrue(f5.alive)
2182
2183 self.assertTrue(f5.detach())
2184 self.assertFalse(f5.alive)
2185
2186 f5() # nothing because previously unregistered
2187 res.append('A')
2188 f3() # => res.append('f3')
2189 self.assertFalse(f3.alive)
2190 res.append('B')
2191 f3() # nothing because previously called
2192 res.append('C')
2193 del a
2194 self._collect_if_necessary()
2195 # => res.append('f4')
2196 # => res.append('f2')
2197 # => res.append('f1')
2198 self.assertFalse(f2.alive)
2199 res.append('D')
2200 f2() # nothing because previously called by gc
2201
2202 expected = ['A', 'f3', 'B', 'C', 'f4', 'f2', 'f1', 'D']
2203 self.assertEqual(res, expected)
2204
2205 def test_all_freed(self):
2206 # we want a weakrefable subclass of weakref.finalize

Callers

nothing calls this directly

Calls 11

_collect_if_necessaryMethod · 0.95
f5Function · 0.85
f3Function · 0.85
AMethod · 0.80
assertTrueMethod · 0.80
assertFalseMethod · 0.80
f2Function · 0.70
finalizeMethod · 0.45
detachMethod · 0.45
appendMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected