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

Method test_basic

Lib/test/test_code.py:1266–1287  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1264class CodeWeakRefTest(unittest.TestCase):
1265
1266 def test_basic(self):
1267 # Create a code object in a clean environment so that we know we have
1268 # the only reference to it left.
1269 namespace = {}
1270 exec("def f(): pass", globals(), namespace)
1271 f = namespace["f"]
1272 del namespace
1273
1274 self.called = False
1275 def callback(code):
1276 self.called = True
1277
1278 # f is now the last reference to the function, and through it, the code
1279 # object. While we hold it, check that we can create a weakref and
1280 # deref it. Then delete it, and check that the callback gets called and
1281 # the reference dies.
1282 coderef = weakref.ref(f.__code__, callback)
1283 self.assertTrue(bool(coderef()))
1284 del f
1285 gc_collect() # For PyPy or other GCs.
1286 self.assertFalse(bool(coderef()))
1287 self.assertTrue(self.called)
1288
1289# Python implementation of location table parsing algorithm
1290def read(it):

Callers

nothing calls this directly

Calls 5

gc_collectFunction · 0.90
globalsFunction · 0.85
assertTrueMethod · 0.80
assertFalseMethod · 0.80
execFunction · 0.50

Tested by

no test coverage detected