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

Method _check_module

Lib/test/test_runpy.py:296–335  ·  view source on GitHub ↗
(self, depth, alter_sys=False,
                         *, namespace=False, parent_namespaces=False)

Source from the content-addressed store, hash-verified

294
295
296 def _check_module(self, depth, alter_sys=False,
297 *, namespace=False, parent_namespaces=False):
298 pkg_dir, mod_fname, mod_name, mod_spec = (
299 self._make_pkg(example_source, depth,
300 namespace=namespace,
301 parent_namespaces=parent_namespaces))
302 forget(mod_name)
303 expected_ns = example_namespace.copy()
304 expected_ns.update({
305 "__name__": mod_name,
306 "__file__": mod_fname,
307 "__package__": mod_name.rpartition(".")[0],
308 "__spec__": mod_spec,
309 })
310 if alter_sys:
311 expected_ns.update({
312 "run_argv0": mod_fname,
313 "run_name_in_sys_modules": True,
314 "module_in_sys_modules": True,
315 })
316 def create_ns(init_globals):
317 return run_module(mod_name, init_globals, alter_sys=alter_sys)
318 try:
319 if verbose > 1: print("Running from source:", mod_name)
320 self.check_code_execution(create_ns, expected_ns)
321 importlib.invalidate_caches()
322 __import__(mod_name)
323 if not sys.dont_write_bytecode:
324 make_legacy_pyc(mod_fname, allow_compile=True)
325 unload(mod_name) # In case loader caches paths
326 os.remove(mod_fname)
327 importlib.invalidate_caches()
328 if verbose > 1: print("Running from compiled:", mod_name)
329 self._fix_ns_for_legacy_pyc(expected_ns, alter_sys)
330 self.check_code_execution(create_ns, expected_ns)
331 else:
332 os.remove(mod_fname)
333 finally:
334 self._del_pkg(pkg_dir)
335 if verbose > 1: print("Module executed successfully")
336
337 def _check_package(self, depth, alter_sys=False,
338 *, namespace=False, parent_namespaces=False):

Callers 3

test_run_moduleMethod · 0.95

Calls 13

_make_pkgMethod · 0.95
_del_pkgMethod · 0.95
forgetFunction · 0.90
make_legacy_pycFunction · 0.90
unloadFunction · 0.90
__import__Function · 0.85
check_code_executionMethod · 0.80
copyMethod · 0.45
updateMethod · 0.45
rpartitionMethod · 0.45
invalidate_cachesMethod · 0.45

Tested by

no test coverage detected