diff options
author | Christian Stenger <christian.stenger@qt.io> | 2023-07-19 09:26:37 +0200 |
---|---|---|
committer | Christian Stenger <christian.stenger@qt.io> | 2023-07-20 08:14:10 +0000 |
commit | b44a7817b8dc3a7898ee6445d2c7494644b10797 (patch) | |
tree | 3f12af7fbb75341d046cc75eb34f3ef5cdfe3fbd | |
parent | 182104e013c65e1b190a6c0aa99e4bab7251e590 (diff) |
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>
-rw-r--r-- | tests/system/shared/utils.py | 8 | ||||
-rw-r--r-- | tests/system/suite_editors/tst_edit_externally/test.py | 3 |
2 files changed, 9 insertions, 2 deletions
diff --git a/tests/system/shared/utils.py b/tests/system/shared/utils.py index 2a17e0333c..8639c6e265 100644 --- a/tests/system/shared/utils.py +++ b/tests/system/shared/utils.py @@ -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: diff --git a/tests/system/suite_editors/tst_edit_externally/test.py b/tests/system/suite_editors/tst_edit_externally/test.py index dea2f5d8ec..e04ab19670 100644 --- a/tests/system/suite_editors/tst_edit_externally/test.py +++ b/tests/system/suite_editors/tst_edit_externally/test.py @@ -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 |