forked from qt-creator/qt-creator
SquishTests: Handle codec problems
Reading files depends on the system encoding and will return a bytes object instead of a str even for text files on some Windows setups. Handle this by explcitly converting to str if needed. Handle possible decoding issues by falling back to UTF8 encoding when running into decoding error while decoding on Windows. Change-Id: I8c1f24ff052710e4b1927399d54e321088e3b171 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -611,8 +611,12 @@ def stringify(obj):
|
||||
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
|
||||
if not platform.system() in ('Microsoft', 'Windows'):
|
||||
return obj.decode()
|
||||
try:
|
||||
return obj.decode('cp1252')
|
||||
except UnicodeDecodeError:
|
||||
return obj.decode('utf-8')
|
||||
|
||||
|
||||
class GitClone:
|
||||
|
@@ -39,7 +39,10 @@ def main():
|
||||
test.fatal("Could not get the editor for '%s'" % currentFile,
|
||||
"Skipping this file for now.")
|
||||
continue
|
||||
|
||||
contentBefore = readFile(currentFile)
|
||||
if not currentFile.endswith(".bin"):
|
||||
contentBefore = stringify(contentBefore)
|
||||
if i % 2 == 0:
|
||||
# modify current file and store content for next modification
|
||||
formerContent = contentBefore
|
||||
|
Reference in New Issue
Block a user