@@ -83,13 +83,11 @@ def bctest(testDir, testObj, buildenv):
83
83
execrun = [execprog ] + execargs
84
84
85
85
# Read the input data (if there is any)
86
- stdinCfg = None
87
86
inputData = None
88
87
if "input" in testObj :
89
88
filename = os .path .join (testDir , testObj ["input" ])
90
89
with open (filename , encoding = "utf8" ) as f :
91
90
inputData = f .read ()
92
- stdinCfg = subprocess .PIPE
93
91
94
92
# Read the expected output data (if there is any)
95
93
outputFn = None
@@ -112,9 +110,8 @@ def bctest(testDir, testObj, buildenv):
112
110
raise Exception
113
111
114
112
# Run the test
115
- proc = subprocess .Popen (execrun , stdin = stdinCfg , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
116
113
try :
117
- outs = proc . communicate ( input = inputData )
114
+ res = subprocess . run ( execrun , capture_output = True , text = True , input = inputData )
118
115
except OSError :
119
116
logging .error ("OSError, Failed to execute " + execprog )
120
117
raise
@@ -123,9 +120,9 @@ def bctest(testDir, testObj, buildenv):
123
120
data_mismatch , formatting_mismatch = False , False
124
121
# Parse command output and expected output
125
122
try :
126
- a_parsed = parse_output (outs [ 0 ] , outputType )
123
+ a_parsed = parse_output (res . stdout , outputType )
127
124
except Exception as e :
128
- logging .error (' Error parsing command output as %s: %s' % ( outputType , e ) )
125
+ logging .error (f" Error parsing command output as { outputType } : ' { str ( e ) } '; res: { str ( res ) } " )
129
126
raise
130
127
try :
131
128
b_parsed = parse_output (outputData , outputType )
@@ -134,13 +131,13 @@ def bctest(testDir, testObj, buildenv):
134
131
raise
135
132
# Compare data
136
133
if a_parsed != b_parsed :
137
- logging .error ("Output data mismatch for " + outputFn + " (format " + outputType + ") " )
134
+ logging .error (f "Output data mismatch for { outputFn } (format { outputType } ); res: { str ( res ) } " )
138
135
data_mismatch = True
139
136
# Compare formatting
140
- if outs [ 0 ] != outputData :
141
- error_message = "Output formatting mismatch for " + outputFn + ": \n "
137
+ if res . stdout != outputData :
138
+ error_message = f "Output formatting mismatch for { outputFn } : \n res: { str ( res ) } \n "
142
139
error_message += "" .join (difflib .context_diff (outputData .splitlines (True ),
143
- outs [ 0 ] .splitlines (True ),
140
+ res . stdout .splitlines (True ),
144
141
fromfile = outputFn ,
145
142
tofile = "returned" ))
146
143
logging .error (error_message )
@@ -152,8 +149,8 @@ def bctest(testDir, testObj, buildenv):
152
149
wantRC = 0
153
150
if "return_code" in testObj :
154
151
wantRC = testObj ['return_code' ]
155
- if proc .returncode != wantRC :
156
- logging .error ("Return code mismatch for " + outputFn )
152
+ if res .returncode != wantRC :
153
+ logging .error (f "Return code mismatch for { outputFn } ; res: { str ( res ) } " )
157
154
raise Exception
158
155
159
156
if "error_txt" in testObj :
@@ -164,8 +161,8 @@ def bctest(testDir, testObj, buildenv):
164
161
# emits DISPLAY errors when running as a windows application on
165
162
# linux through wine. Just assert that the expected error text appears
166
163
# somewhere in stderr.
167
- if want_error not in outs [ 1 ] :
168
- logging .error ("Error mismatch:\n " + "Expected: " + want_error + " \n Received: " + outs [ 1 ]. rstrip ())
164
+ if want_error not in res . stderr :
165
+ logging .error (f "Error mismatch:\n Expected: { want_error } \n Received: { res . stderr . rstrip ()} \n res: { str ( res ) } " )
169
166
raise Exception
170
167
171
168
def parse_output (a , fmt ):
0 commit comments