aboutsummaryrefslogtreecommitdiff
path: root/tests/fruit_test_common.py
diff options
context:
space:
mode:
authorMarco Poletti <poletti.marco@gmail.com>2016-11-06 09:54:42 +0000
committerMarco Poletti <poletti.marco@gmail.com>2016-11-06 09:54:52 +0000
commit8b630710a4256498c887c5df9ccb22d1ba6f7465 (patch)
tree6eb3807a4ed130d61bd31c5345f62768642d2a6f /tests/fruit_test_common.py
parent36efab5c1bfa38266bf1ef47161cdc32b0373cf0 (diff)
downloadgoogle-fruit-8b630710a4256498c887c5df9ccb22d1ba6f7465.tar.gz
Always print stdout/stderr as strings in e2e tests (when they fail), instead of occasionally printing them as bytes.
Diffstat (limited to 'tests/fruit_test_common.py')
-rw-r--r--tests/fruit_test_common.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/tests/fruit_test_common.py b/tests/fruit_test_common.py
index 2a0dca5..683a75d 100644
--- a/tests/fruit_test_common.py
+++ b/tests/fruit_test_common.py
@@ -45,6 +45,11 @@ def rethrow_sh_exception(e):
If we didn't re-throw the exception this way, sh will clip the command+stdout+stderr message at 750 chars, which
sometimes makes it hard to understand what the error was.
"""
+
+ # We use str(..., 'utf-8') to convert both str and bytes objects to str.
+ stdout = str(e.stdout or '', 'utf-8')
+ stderr = str(e.stderr or '', 'utf-8')
+
message = textwrap.dedent('''\
Ran command: {command}
Stdout:
@@ -52,7 +57,7 @@ def rethrow_sh_exception(e):
Stderr:
{stderr}
- ''').format(command=e.full_cmd, stdout=e.stdout or '', stderr=e.stderr or '')
+ ''').format(command=e.full_cmd, stdout=stdout, stderr=stderr)
# The "from None" here prevents the original exception from being shown if this function is called in an except
# clause.
raise Exception(message) from None
@@ -85,7 +90,7 @@ def expect_compile_error(expected_fruit_error_regex, expected_fruit_error_desc_r
except sh.ErrorReturnCode as e1:
e = e1
- stderr = e.stderr.decode()
+ stderr = str(e.stderr, 'utf-8')
stderr_lines = stderr.splitlines()
# Different compilers output a different number of spaces when pretty-printing types.
# When using libc++, sometimes std::foo identifiers are reported as std::__1::foo.