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

Method check_code_execution

Lib/test/test_runpy.py:127–151  ·  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

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