Skip to content

Commit b5bf2cb

Browse files
refi64neolynx
authored andcommitted
Fix functional tests' '--capture' on Python 3
None of the commands' output is ever treated as binary, so we can just always decode it as text. Signed-off-by: Ryan Gonzalez <ryan.gonzalez@collabora.com>
1 parent fb3436b commit b5bf2cb

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

system/lib.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,14 @@ def prepare_fixture(self):
248248
for cmd in self.fixtureCmds:
249249
output = self.run_cmd(cmd)
250250
print("fixture Output:\n")
251-
for line in output.decode("utf-8").split("\n"):
251+
for line in output.split("\n"):
252252
print(f" {line}")
253253

254254
def sort_lines(self, output):
255255
return "\n".join(sorted(self.ensure_utf8(output).split("\n")))
256256

257257
def run(self):
258-
output = self.run_cmd(self.runCmd, self.expectedCode).decode("utf-8")
258+
output = self.run_cmd(self.runCmd, self.expectedCode)
259259
if self.sortOutput:
260260
output = self.sort_lines(output)
261261
self.output = self.output_processor(output)
@@ -289,6 +289,8 @@ def run_cmd(self, command, expected_code=0):
289289
proc = self._start_process(command, stdout=subprocess.PIPE)
290290
raw_output, _ = proc.communicate()
291291

292+
raw_output = raw_output.decode("utf-8")
293+
292294
returncodes = [proc.returncode]
293295
is_aptly_command = False
294296
if isinstance(command, str):
@@ -300,12 +302,12 @@ def run_cmd(self, command, expected_code=0):
300302
if is_aptly_command:
301303
# remove the last two rows as go tests always print PASS/FAIL and coverage in those
302304
# two lines. This would otherwise fail the tests as they would not match gold
303-
match = re.search(r"EXIT: (\d)\n.*\n.*coverage: .*", raw_output.decode("utf-8"))
304-
if match is None:
305-
raise Exception("no matches found in output '%s'" % raw_output.decode("utf-8"))
305+
matches = re.findall(r"((.|\n)*)EXIT: (\d)\n.*\ncoverage: .*", raw_output)
306+
if not matches:
307+
raise Exception("no matches found in output '%s'" % raw_output)
306308

307-
output = match.string[:match.start()].encode()
308-
returncodes.append(int(match.group(1)))
309+
output, _, returncode = matches[0]
310+
returncodes.append(int(returncode))
309311
else:
310312
output = raw_output
311313

@@ -356,7 +358,7 @@ def check_output(self):
356358
raise
357359

358360
def check_cmd_output(self, command, gold_name, match_prepare=None, expected_code=0):
359-
output = self.run_cmd(command, expected_code=expected_code).decode("utf-8")
361+
output = self.run_cmd(command, expected_code=expected_code)
360362
try:
361363
self.verify_match(self.get_gold(gold_name), output, match_prepare)
362364
except: # noqa: E722

0 commit comments

Comments
 (0)