Skip to content

Commit

Permalink
Fix functional tests' '--capture' on Python 3
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
refi64 authored and neolynx committed Jun 15, 2024
1 parent 9a3dfcd commit a5bd37f
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions system/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,14 @@ def prepare_fixture(self):
for cmd in self.fixtureCmds:
output = self.run_cmd(cmd)
print("\n")
for line in output.decode("utf-8").split("\n"):
for line in output.split("\n"):
print(f" {line}")

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

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:
output = self.sort_lines(output)
self.output = self.output_processor(output)
Expand Down Expand Up @@ -288,6 +288,8 @@ def run_cmd(self, command, expected_code=0):
proc = self._start_process(command, stdout=subprocess.PIPE)
raw_output, _ = proc.communicate()

raw_output = raw_output.decode("utf-8")

returncodes = [proc.returncode]
is_aptly_command = False
if isinstance(command, str):
Expand All @@ -299,12 +301,12 @@ def run_cmd(self, command, expected_code=0):
if is_aptly_command:
# 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
match = re.search(r"EXIT: (\d)\n.*\n.*coverage: .*", raw_output.decode("utf-8"))
if match is None:
raise Exception("no matches found in output '%s'" % raw_output.decode("utf-8"))
matches = re.findall(r"((.|\n)*)EXIT: (\d)\n.*\ncoverage: .*", raw_output)
if not matches:
raise Exception("no matches found in output '%s'" % raw_output)

output = match.string[:match.start()].encode()
returncodes.append(int(match.group(1)))
output, _, returncode = matches[0]
returncodes.append(int(returncode))
else:
output = raw_output

Expand Down Expand Up @@ -355,7 +357,7 @@ def check_output(self):
raise

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:
self.verify_match(self.get_gold(gold_name), output, match_prepare)
except: # noqa: E722
Expand Down

0 comments on commit a5bd37f

Please sign in to comment.