From 239282813fd36d781783425a656caf32addc02d1 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Wed, 24 May 2023 14:44:33 +0200 Subject: [PATCH] [python tests] decode shell output as UTF-8 (#26783) If tests are run on a platform which is returning special characters (e.g. date with months which contain an umlaut) runnig the test fails: ``` File "/home/sag/projects/project-chip/connectedhomeip/./scripts/tests/run_python_test.py", line 95, in main print(subprocess.check_output(["ls -l"], shell=True).decode('us-ascii')) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1553: ordinal not in range(128) ``` Decode the output using UTF-8 by default. --- scripts/tests/run_java_test.py | 2 +- scripts/tests/run_python_test.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/tests/run_java_test.py b/scripts/tests/run_java_test.py index bb0021526f2276..8f30de2a1c643b 100755 --- a/scripts/tests/run_java_test.py +++ b/scripts/tests/run_java_test.py @@ -55,7 +55,7 @@ def main(app: str, app_args: str, tool_path: str, tool_cluster: str, tool_args: raise Exception("Failed to remove /tmp/chip* for factory reset.") print("Contents of test directory: %s" % os.getcwd()) - print(subprocess.check_output(["ls -l"], shell=True).decode('us-ascii')) + print(subprocess.check_output(["ls -l"], shell=True).decode('utf-8')) # Remove native app KVS if that was used kvs_match = re.search(r"--KVS (?P[^ ]+)", app_args) diff --git a/scripts/tests/run_python_test.py b/scripts/tests/run_python_test.py index 87f6044c2a35f0..c607a5d07cf40f 100755 --- a/scripts/tests/run_python_test.py +++ b/scripts/tests/run_python_test.py @@ -92,7 +92,7 @@ def main(app: str, factoryreset: bool, app_args: str, script: str, script_args: raise Exception("Failed to remove /tmp/chip* for factory reset.") print("Contents of test directory: %s" % os.getcwd()) - print(subprocess.check_output(["ls -l"], shell=True).decode('us-ascii')) + print(subprocess.check_output(["ls -l"], shell=True).decode('utf-8')) # Remove native app KVS if that was used kvs_match = re.search(r"--KVS (?P[^ ]+)", app_args)