@@ -56,8 +56,35 @@ def interpreter_requires_environment():
56
56
return __cached_interp_requires_environment
57
57
58
58
59
- _PythonRunResult = collections .namedtuple ("_PythonRunResult" ,
60
- ("rc" , "out" , "err" ))
59
+ class _PythonRunResult (collections .namedtuple ("_PythonRunResult" ,
60
+ ("rc" , "out" , "err" ))):
61
+ """Helper for reporting Python subprocess run results"""
62
+ def fail (self , cmd_line ):
63
+ """Provide helpful details about failed subcommand runs"""
64
+ # Limit to 80 lines to ASCII characters
65
+ maxlen = 80 * 100
66
+ out , err = self .out , self .err
67
+ if len (out ) > maxlen :
68
+ out = b'(... truncated stdout ...)' + out [- maxlen :]
69
+ if len (err ) > maxlen :
70
+ err = b'(... truncated stderr ...)' + err [- maxlen :]
71
+ out = out .decode ('ascii' , 'replace' ).rstrip ()
72
+ err = err .decode ('ascii' , 'replace' ).rstrip ()
73
+ raise AssertionError ("Process return code is %d\n "
74
+ "command line: %r\n "
75
+ "\n "
76
+ "stdout:\n "
77
+ "---\n "
78
+ "%s\n "
79
+ "---\n "
80
+ "\n "
81
+ "stderr:\n "
82
+ "---\n "
83
+ "%s\n "
84
+ "---"
85
+ % (self .rc , cmd_line ,
86
+ out ,
87
+ err ))
61
88
62
89
63
90
# Executing the interpreter in a subprocess
@@ -115,30 +142,7 @@ def run_python_until_end(*args, **env_vars):
115
142
def _assert_python (expected_success , * args , ** env_vars ):
116
143
res , cmd_line = run_python_until_end (* args , ** env_vars )
117
144
if (res .rc and expected_success ) or (not res .rc and not expected_success ):
118
- # Limit to 80 lines to ASCII characters
119
- maxlen = 80 * 100
120
- out , err = res .out , res .err
121
- if len (out ) > maxlen :
122
- out = b'(... truncated stdout ...)' + out [- maxlen :]
123
- if len (err ) > maxlen :
124
- err = b'(... truncated stderr ...)' + err [- maxlen :]
125
- out = out .decode ('ascii' , 'replace' ).rstrip ()
126
- err = err .decode ('ascii' , 'replace' ).rstrip ()
127
- raise AssertionError ("Process return code is %d\n "
128
- "command line: %r\n "
129
- "\n "
130
- "stdout:\n "
131
- "---\n "
132
- "%s\n "
133
- "---\n "
134
- "\n "
135
- "stderr:\n "
136
- "---\n "
137
- "%s\n "
138
- "---"
139
- % (res .rc , cmd_line ,
140
- out ,
141
- err ))
145
+ res .fail (cmd_line )
142
146
return res
143
147
144
148
def assert_python_ok (* args , ** env_vars ):
0 commit comments