From 113c867bdacc14fb8ebae1ee4d7d10a8000818cd Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Wed, 13 Apr 2022 07:07:22 +0200 Subject: [PATCH] Squish: Ensure we get str output from commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I4e7ff85d2e2afbf714e9d16ae07e56d93cc57655 Reviewed-by: Robert Löhning --- tests/system/shared/utils.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/system/shared/utils.py b/tests/system/shared/utils.py index 33c24a7c5c8..ced74a0031e 100644 --- a/tests/system/shared/utils.py +++ b/tests/system/shared/utils.py @@ -226,11 +226,11 @@ def logApplicationOutput(): # get the output from a given cmdline call def getOutputFromCmdline(cmdline, environment=None, acceptedError=0): try: - return subprocess.check_output(cmdline, env=environment) + return stringify(subprocess.check_output(cmdline, env=environment)) except subprocess.CalledProcessError as e: if e.returncode != acceptedError: test.warning("Command '%s' returned %d" % (e.cmd, e.returncode)) - return e.output + return stringify(e.output) def selectFromFileDialog(fileName, waitForFile=False, ignoreFinalSnooze=False): def __closePopupIfNecessary__(): @@ -672,3 +672,12 @@ def isString(sth): return isinstance(sth, str) else: return isinstance(sth, (str, unicode)) + +# helper function to ensure we get str, converts bytes if necessary +def stringify(obj): + stringTypes = (str, unicode) if sys.version_info.major == 2 else (str) + if isinstance(obj, stringTypes): + return obj + if isinstance(obj, bytes): + tmp = obj.decode('cp1252') if platform.system() in ('Microsoft','Windows') else obj.decode() + return tmp