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

Method _check_script

Lib/test/test_runpy.py:611–653  ·  view source on GitHub ↗
(self, script_name, expected_name, expected_file,
                            expected_argv0, mod_name=None,
                            expect_spec=True, check_loader=True)

Source from the content-addressed store, hash-verified

609 source, omit_suffix)
610
611 def _check_script(self, script_name, expected_name, expected_file,
612 expected_argv0, mod_name=None,
613 expect_spec=True, check_loader=True):
614 # First check is without run_name
615 def create_ns(init_globals):
616 return run_path(script_name, init_globals)
617 expected_ns = example_namespace.copy()
618 if mod_name is None:
619 spec_name = expected_name
620 else:
621 spec_name = mod_name
622 if expect_spec:
623 mod_spec = importlib.util.spec_from_file_location(spec_name,
624 expected_file)
625 mod_cached = mod_spec.cached
626 if not check_loader:
627 mod_spec.loader = None
628 else:
629 mod_spec = mod_cached = None
630
631 expected_ns.update({
632 "__name__": expected_name,
633 "__file__": expected_file,
634 "__package__": "",
635 "__spec__": mod_spec,
636 "run_argv0": expected_argv0,
637 "run_name_in_sys_modules": True,
638 "module_in_sys_modules": True,
639 })
640 self.check_code_execution(create_ns, expected_ns)
641 # Second check makes sure run_name works in all cases
642 run_name = "prove.issue15230.is.fixed"
643 def create_ns(init_globals):
644 return run_path(script_name, init_globals, run_name)
645 if expect_spec and mod_name is None:
646 mod_spec = importlib.util.spec_from_file_location(run_name,
647 expected_file)
648 if not check_loader:
649 mod_spec.loader = None
650 expected_ns["__spec__"] = mod_spec
651 expected_ns["__name__"] = run_name
652 expected_ns["__package__"] = run_name.rpartition(".")[0]
653 self.check_code_execution(create_ns, expected_ns)
654
655 def _check_import_error(self, script_name, msg):
656 msg = re.escape(msg)

Callers 8

test_basic_scriptMethod · 0.95
test_script_compiledMethod · 0.95
test_directoryMethod · 0.95
test_zipfileMethod · 0.95
test_zipfile_compiledMethod · 0.95

Calls 4

check_code_executionMethod · 0.80
copyMethod · 0.45
updateMethod · 0.45
rpartitionMethod · 0.45

Tested by

no test coverage detected