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

Method run_py

Lib/test/test_launcher.py:218–264  ·  view source on GitHub ↗
(self, args, env=None, allow_fail=False, expect_returncode=0, argv=None)

Source from the content-addressed store, hash-verified

216 return self.py_exe
217
218 def run_py(self, args, env=None, allow_fail=False, expect_returncode=0, argv=None):
219 if not self.py_exe:
220 self.py_exe = self.find_py()
221
222 ignore = {"VIRTUAL_ENV", "PY_PYTHON", "PY_PYTHON2", "PY_PYTHON3"}
223 env = {
224 **{k.upper(): v for k, v in os.environ.items() if k.upper() not in ignore},
225 "PYLAUNCHER_DEBUG": "1",
226 "PYLAUNCHER_DRYRUN": "1",
227 "PYLAUNCHER_LIMIT_TO_COMPANY": "",
228 **{k.upper(): v for k, v in (env or {}).items()},
229 }
230 if ini_dir := getattr(self, '_ini_dir', None):
231 env.setdefault("_PYLAUNCHER_INIDIR", ini_dir)
232 if not argv:
233 argv = [self.py_exe, *args]
234 with subprocess.Popen(
235 argv,
236 env=env,
237 executable=self.py_exe,
238 stdin=subprocess.PIPE,
239 stdout=subprocess.PIPE,
240 stderr=subprocess.PIPE,
241 ) as p:
242 p.stdin.close()
243 p.wait(10)
244 out = p.stdout.read().decode("utf-8", "replace")
245 err = p.stderr.read().decode("ascii", "replace").replace("\uFFFD", "?")
246 if p.returncode != expect_returncode and support.verbose and not allow_fail:
247 print("++ COMMAND ++")
248 print([self.py_exe, *args])
249 print("++ STDOUT ++")
250 print(out)
251 print("++ STDERR ++")
252 print(err)
253 if allow_fail and p.returncode != expect_returncode:
254 raise subprocess.CalledProcessError(p.returncode, [self.py_exe, *args], out, err)
255 else:
256 self.assertEqual(expect_returncode, p.returncode)
257 data = {
258 s.partition(":")[0]: s.partition(":")[2].lstrip()
259 for s in err.splitlines()
260 if not s.startswith("#") and ":" in s
261 }
262 data["stdout"] = out
263 data["stderr"] = err
264 return data
265
266 def py_ini(self, content):
267 ini_dir = getattr(self, '_ini_dir', None)

Callers 15

test_versionMethod · 0.80
test_help_optionMethod · 0.80
test_list_optionMethod · 0.80
test_listMethod · 0.80
test_list_pathsMethod · 0.80
test_filter_to_tagMethod · 0.80
test_search_major_3Method · 0.80

Calls 14

find_pyMethod · 0.95
upperMethod · 0.45
itemsMethod · 0.45
setdefaultMethod · 0.45
closeMethod · 0.45
waitMethod · 0.45
decodeMethod · 0.45
readMethod · 0.45
replaceMethod · 0.45
assertEqualMethod · 0.45
partitionMethod · 0.45
lstripMethod · 0.45

Tested by

no test coverage detected