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

Method test_module_with_large_stack

Lib/test/test_import/__init__.py:494–531  ·  view source on GitHub ↗
(self, module='longlist')

Source from the content-addressed store, hash-verified

492 del sys.path[0]
493
494 def test_module_with_large_stack(self, module='longlist'):
495 # Regression test for http://bugs.python.org/issue561858.
496 filename = module + '.py'
497
498 # Create a file with a list of 65000 elements.
499 with open(filename, 'w', encoding='utf-8') as f:
500 f.write('d = [\n')
501 for i in range(65000):
502 f.write('"",\n')
503 f.write(']')
504
505 try:
506 # Compile & remove .py file; we only need .pyc.
507 # Bytecode must be relocated from the PEP 3147 bytecode-only location.
508 make_legacy_pyc(filename, allow_compile=True)
509 finally:
510 unlink(filename)
511
512 # Need to be able to load from current dir.
513 sys.path.append('')
514 importlib.invalidate_caches()
515
516 namespace = {}
517 try:
518 # This used to crash.
519 exec('import ' + module, None, namespace)
520 finally:
521 # Cleanup.
522 del sys.path[-1]
523 unlink(filename + 'c')
524 unlink(filename + 'o')
525
526 # Remove references to the module (unload the module)
527 namespace.clear()
528 try:
529 del sys.modules[module]
530 except KeyError:
531 pass
532
533 def test_failing_import_sticks(self):
534 source = TESTFN + ".py"

Callers

nothing calls this directly

Calls 7

make_legacy_pycFunction · 0.90
unlinkFunction · 0.85
openFunction · 0.50
writeMethod · 0.45
appendMethod · 0.45
invalidate_cachesMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected