(self, args, env=None, allow_fail=False, expect_returncode=0, argv=None)
| 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) |
no test coverage detected