bpo-28180: Implementation for PEP 538 (#659) · python/cpython@6ea4186 (original) (raw)
`@@ -48,8 +48,35 @@ def interpreter_requires_environment():
`
48
48
`return __cached_interp_requires_environment
`
49
49
``
50
50
``
51
``
`-
_PythonRunResult = collections.namedtuple("_PythonRunResult",
`
52
``
`-
("rc", "out", "err"))
`
``
51
`+
class _PythonRunResult(collections.namedtuple("_PythonRunResult",
`
``
52
`+
("rc", "out", "err"))):
`
``
53
`+
"""Helper for reporting Python subprocess run results"""
`
``
54
`+
def fail(self, cmd_line):
`
``
55
`+
"""Provide helpful details about failed subcommand runs"""
`
``
56
`+
Limit to 80 lines to ASCII characters
`
``
57
`+
maxlen = 80 * 100
`
``
58
`+
out, err = self.out, self.err
`
``
59
`+
if len(out) > maxlen:
`
``
60
`+
out = b'(... truncated stdout ...)' + out[-maxlen:]
`
``
61
`+
if len(err) > maxlen:
`
``
62
`+
err = b'(... truncated stderr ...)' + err[-maxlen:]
`
``
63
`+
out = out.decode('ascii', 'replace').rstrip()
`
``
64
`+
err = err.decode('ascii', 'replace').rstrip()
`
``
65
`+
raise AssertionError("Process return code is %d\n"
`
``
66
`+
"command line: %r\n"
`
``
67
`+
"\n"
`
``
68
`+
"stdout:\n"
`
``
69
`+
"---\n"
`
``
70
`+
"%s\n"
`
``
71
`+
"---\n"
`
``
72
`+
"\n"
`
``
73
`+
"stderr:\n"
`
``
74
`+
"---\n"
`
``
75
`+
"%s\n"
`
``
76
`+
"---"
`
``
77
`+
% (self.rc, cmd_line,
`
``
78
`+
out,
`
``
79
`+
err))
`
53
80
``
54
81
``
55
82
`# Executing the interpreter in a subprocess
`
`@@ -107,30 +134,7 @@ def run_python_until_end(*args, **env_vars):
`
107
134
`def _assert_python(expected_success, *args, **env_vars):
`
108
135
`res, cmd_line = run_python_until_end(*args, **env_vars)
`
109
136
`if (res.rc and expected_success) or (not res.rc and not expected_success):
`
110
``
`-
Limit to 80 lines to ASCII characters
`
111
``
`-
maxlen = 80 * 100
`
112
``
`-
out, err = res.out, res.err
`
113
``
`-
if len(out) > maxlen:
`
114
``
`-
out = b'(... truncated stdout ...)' + out[-maxlen:]
`
115
``
`-
if len(err) > maxlen:
`
116
``
`-
err = b'(... truncated stderr ...)' + err[-maxlen:]
`
117
``
`-
out = out.decode('ascii', 'replace').rstrip()
`
118
``
`-
err = err.decode('ascii', 'replace').rstrip()
`
119
``
`-
raise AssertionError("Process return code is %d\n"
`
120
``
`-
"command line: %r\n"
`
121
``
`-
"\n"
`
122
``
`-
"stdout:\n"
`
123
``
`-
"---\n"
`
124
``
`-
"%s\n"
`
125
``
`-
"---\n"
`
126
``
`-
"\n"
`
127
``
`-
"stderr:\n"
`
128
``
`-
"---\n"
`
129
``
`-
"%s\n"
`
130
``
`-
"---"
`
131
``
`-
% (res.rc, cmd_line,
`
132
``
`-
out,
`
133
``
`-
err))
`
``
137
`+
res.fail(cmd_line)
`
134
138
`return res
`
135
139
``
136
140
`def assert_python_ok(*args, **env_vars):
`