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>
This commit is contained in:
Ryan Gonzalez
2022-05-17 17:51:30 -05:00
committed by André Roth
parent fb3436b23d
commit b5bf2cbcda

View File

@@ -248,14 +248,14 @@ class BaseTest(object):
for cmd in self.fixtureCmds: for cmd in self.fixtureCmds:
output = self.run_cmd(cmd) output = self.run_cmd(cmd)
print("fixture Output:\n") print("fixture Output:\n")
for line in output.decode("utf-8").split("\n"): for line in output.split("\n"):
print(f" {line}") print(f" {line}")
def sort_lines(self, output): def sort_lines(self, output):
return "\n".join(sorted(self.ensure_utf8(output).split("\n"))) return "\n".join(sorted(self.ensure_utf8(output).split("\n")))
def run(self): def run(self):
output = self.run_cmd(self.runCmd, self.expectedCode).decode("utf-8") output = self.run_cmd(self.runCmd, self.expectedCode)
if self.sortOutput: if self.sortOutput:
output = self.sort_lines(output) output = self.sort_lines(output)
self.output = self.output_processor(output) self.output = self.output_processor(output)
@@ -289,6 +289,8 @@ class BaseTest(object):
proc = self._start_process(command, stdout=subprocess.PIPE) proc = self._start_process(command, stdout=subprocess.PIPE)
raw_output, _ = proc.communicate() raw_output, _ = proc.communicate()
raw_output = raw_output.decode("utf-8")
returncodes = [proc.returncode] returncodes = [proc.returncode]
is_aptly_command = False is_aptly_command = False
if isinstance(command, str): if isinstance(command, str):
@@ -300,12 +302,12 @@ class BaseTest(object):
if is_aptly_command: if is_aptly_command:
# remove the last two rows as go tests always print PASS/FAIL and coverage in those # remove the last two rows as go tests always print PASS/FAIL and coverage in those
# two lines. This would otherwise fail the tests as they would not match gold # two lines. This would otherwise fail the tests as they would not match gold
match = re.search(r"EXIT: (\d)\n.*\n.*coverage: .*", raw_output.decode("utf-8")) matches = re.findall(r"((.|\n)*)EXIT: (\d)\n.*\ncoverage: .*", raw_output)
if match is None: if not matches:
raise Exception("no matches found in output '%s'" % raw_output.decode("utf-8")) raise Exception("no matches found in output '%s'" % raw_output)
output = match.string[:match.start()].encode() output, _, returncode = matches[0]
returncodes.append(int(match.group(1))) returncodes.append(int(returncode))
else: else:
output = raw_output output = raw_output
@@ -356,7 +358,7 @@ class BaseTest(object):
raise raise
def check_cmd_output(self, command, gold_name, match_prepare=None, expected_code=0): def check_cmd_output(self, command, gold_name, match_prepare=None, expected_code=0):
output = self.run_cmd(command, expected_code=expected_code).decode("utf-8") output = self.run_cmd(command, expected_code=expected_code)
try: try:
self.verify_match(self.get_gold(gold_name), output, match_prepare) self.verify_match(self.get_gold(gold_name), output, match_prepare)
except: # noqa: E722 except: # noqa: E722