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

Method _check_module

Lib/test/test_runpy.py:296–334  ·  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 "__cached__": mod_spec.cached,
308 "__package__": mod_name.rpartition(".")[0],
309 "__spec__": mod_spec,
310 })
311 if alter_sys:
312 expected_ns.update({
313 "run_argv0": mod_fname,
314 "run_name_in_sys_modules": True,
315 "module_in_sys_modules": True,
316 })
317 def create_ns(init_globals):
318 return run_module(mod_name, init_globals, alter_sys=alter_sys)
319 try:
320 if verbose > 1: print("Running from source:", mod_name)
321 self.check_code_execution(create_ns, expected_ns)
322 importlib.invalidate_caches()
323 __import__(mod_name)
324 os.remove(mod_fname)
325 if not sys.dont_write_bytecode:
326 make_legacy_pyc(mod_fname)
327 unload(mod_name) # In case loader caches paths
328 importlib.invalidate_caches()
329 if verbose > 1: print("Running from compiled:", mod_name)
330 self._fix_ns_for_legacy_pyc(expected_ns, alter_sys)
331 self.check_code_execution(create_ns, expected_ns)
332 finally:
333 self._del_pkg(pkg_dir)
334 if verbose > 1: print("Module executed successfully")
335
336 def _check_package(self, depth, alter_sys=False,
337 *, namespace=False, parent_namespaces=False):

Callers 3

test_run_moduleMethod · 0.95

Calls 14

_make_pkgMethod · 0.95
_del_pkgMethod · 0.95
forgetFunction · 0.90
make_legacy_pycFunction · 0.90
unloadFunction · 0.90
check_code_executionMethod · 0.80
printFunction · 0.50
__import__Function · 0.50
copyMethod · 0.45
updateMethod · 0.45
rpartitionMethod · 0.45

Tested by

no test coverage detected