forked from qt-creator/qt-creator
Squish: Ensure we get str output from commands
Change-Id: I4e7ff85d2e2afbf714e9d16ae07e56d93cc57655 Reviewed-by: Robert Löhning <robert.loehning@qt.io>
This commit is contained in:
@@ -226,11 +226,11 @@ def logApplicationOutput():
|
|||||||
# get the output from a given cmdline call
|
# get the output from a given cmdline call
|
||||||
def getOutputFromCmdline(cmdline, environment=None, acceptedError=0):
|
def getOutputFromCmdline(cmdline, environment=None, acceptedError=0):
|
||||||
try:
|
try:
|
||||||
return subprocess.check_output(cmdline, env=environment)
|
return stringify(subprocess.check_output(cmdline, env=environment))
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
if e.returncode != acceptedError:
|
if e.returncode != acceptedError:
|
||||||
test.warning("Command '%s' returned %d" % (e.cmd, e.returncode))
|
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 selectFromFileDialog(fileName, waitForFile=False, ignoreFinalSnooze=False):
|
||||||
def __closePopupIfNecessary__():
|
def __closePopupIfNecessary__():
|
||||||
@@ -672,3 +672,12 @@ def isString(sth):
|
|||||||
return isinstance(sth, str)
|
return isinstance(sth, str)
|
||||||
else:
|
else:
|
||||||
return isinstance(sth, (str, unicode))
|
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
|
||||||
|
Reference in New Issue
Block a user