mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Add some docstrings, clarify others, and fix formatting.
This commit is contained in:
parent
01ea326a8e
commit
8f2c2bcc9d
1 changed files with 11 additions and 3 deletions
|
@ -39,7 +39,7 @@ def _assert_python(expected_success, *args, **env_vars):
|
||||||
p.stdout.close()
|
p.stdout.close()
|
||||||
p.stderr.close()
|
p.stderr.close()
|
||||||
rc = p.returncode
|
rc = p.returncode
|
||||||
err = strip_python_stderr(err)
|
err = strip_python_stderr(err)
|
||||||
if (rc and expected_success) or (not rc and not expected_success):
|
if (rc and expected_success) or (not rc and not expected_success):
|
||||||
raise AssertionError(
|
raise AssertionError(
|
||||||
"Process return code is %d, "
|
"Process return code is %d, "
|
||||||
|
@ -49,18 +49,25 @@ def _assert_python(expected_success, *args, **env_vars):
|
||||||
def assert_python_ok(*args, **env_vars):
|
def assert_python_ok(*args, **env_vars):
|
||||||
"""
|
"""
|
||||||
Assert that running the interpreter with `args` and optional environment
|
Assert that running the interpreter with `args` and optional environment
|
||||||
variables `env_vars` is ok and return a (return code, stdout, stderr) tuple.
|
variables `env_vars` succeeds (rc == 0) and return a (return code, stdout,
|
||||||
|
stderr) tuple.
|
||||||
"""
|
"""
|
||||||
return _assert_python(True, *args, **env_vars)
|
return _assert_python(True, *args, **env_vars)
|
||||||
|
|
||||||
def assert_python_failure(*args, **env_vars):
|
def assert_python_failure(*args, **env_vars):
|
||||||
"""
|
"""
|
||||||
Assert that running the interpreter with `args` and optional environment
|
Assert that running the interpreter with `args` and optional environment
|
||||||
variables `env_vars` fails and return a (return code, stdout, stderr) tuple.
|
variables `env_vars` fails (rc != 0) and return a (return code, stdout,
|
||||||
|
stderr) tuple.
|
||||||
"""
|
"""
|
||||||
return _assert_python(False, *args, **env_vars)
|
return _assert_python(False, *args, **env_vars)
|
||||||
|
|
||||||
def spawn_python(*args, **kw):
|
def spawn_python(*args, **kw):
|
||||||
|
"""Run a Python subprocess with the given arguments.
|
||||||
|
|
||||||
|
kw is extra keyword args to pass to subprocess.Popen. Returns a Popen
|
||||||
|
object.
|
||||||
|
"""
|
||||||
cmd_line = [sys.executable, '-E']
|
cmd_line = [sys.executable, '-E']
|
||||||
cmd_line.extend(args)
|
cmd_line.extend(args)
|
||||||
return subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
|
return subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
|
||||||
|
@ -68,6 +75,7 @@ def spawn_python(*args, **kw):
|
||||||
**kw)
|
**kw)
|
||||||
|
|
||||||
def kill_python(p):
|
def kill_python(p):
|
||||||
|
"""Run the given Popen process until completion and return stdout."""
|
||||||
p.stdin.close()
|
p.stdin.close()
|
||||||
data = p.stdout.read()
|
data = p.stdout.read()
|
||||||
p.stdout.close()
|
p.stdout.close()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue