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

Method check_code_execution

Lib/test/test_runpy.py:128–152  ·  view source on GitHub ↗

Check that an interface runs the example code correctly First argument is a callable accepting the initial globals and using them to create the actual namespace Second argument is the expected result

(self, create_namespace, expected_namespace)

Source from the content-addressed store, hash-verified

126 self.assertEqual(actual, expected)
127
128 def check_code_execution(self, create_namespace, expected_namespace):
129 """Check that an interface runs the example code correctly
130
131 First argument is a callable accepting the initial globals and
132 using them to create the actual namespace
133 Second argument is the expected result
134 """
135 sentinel = object()
136 expected_ns = expected_namespace.copy()
137 run_name = expected_ns["__name__"]
138 saved_argv0 = sys.argv[0]
139 saved_mod = sys.modules.get(run_name, sentinel)
140 # Check without initial globals
141 result_ns = create_namespace(None)
142 self.assertNamespaceMatches(result_ns, expected_ns)
143 self.assertIs(sys.argv[0], saved_argv0)
144 self.assertIs(sys.modules.get(run_name, sentinel), saved_mod)
145 # And then with initial globals
146 initial_ns = {"sentinel": sentinel}
147 expected_ns["sentinel"] = sentinel
148 result_ns = create_namespace(initial_ns)
149 self.assertIsNot(result_ns, initial_ns)
150 self.assertNamespaceMatches(result_ns, expected_ns)
151 self.assertIs(sys.argv[0], saved_argv0)
152 self.assertIs(sys.modules.get(run_name, sentinel), saved_mod)
153
154
155class ExecutionLayerTestCase(unittest.TestCase, CodeExecutionMixin):

Callers 6

test_run_codeMethod · 0.80
test_run_module_codeMethod · 0.80
_check_moduleMethod · 0.80
_check_packageMethod · 0.80
test_run_nameMethod · 0.80
_check_scriptMethod · 0.80

Calls 5

assertIsNotMethod · 0.80
copyMethod · 0.45
getMethod · 0.45
assertIsMethod · 0.45

Tested by

no test coverage detected