From 0408b4a757645f10927763cb4befceff0f75e855 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Wed, 11 Aug 2021 13:40:30 +0200 Subject: [PATCH] Squish: Improve Python2/Python3 compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I49dc9ee2f4ef52900b403ed94f0c6cd5925239b6 Reviewed-by: Robert Löhning --- tests/system/shared/classes.py | 5 ++++- tests/system/shared/qtcreator.py | 9 ++++++--- tests/system/shared/suites_qtta.py | 2 -- tests/system/shared/workarounds.py | 17 +++++++++++------ .../suite_editors/tst_revert_changes/test.py | 1 - 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/tests/system/shared/classes.py b/tests/system/shared/classes.py index 3a675c61e5e..a96a7e2d6e0 100644 --- a/tests/system/shared/classes.py +++ b/tests/system/shared/classes.py @@ -23,7 +23,10 @@ # ############################################################################ -import __builtin__ +try: + import __builtin__ # Python 2 +except ImportError: + import builtins as __builtin__ # Python 3 # for easier re-usage (because Python hasn't an enum type) class Targets: diff --git a/tests/system/shared/qtcreator.py b/tests/system/shared/qtcreator.py index 8959e3669dc..0618ce273da 100644 --- a/tests/system/shared/qtcreator.py +++ b/tests/system/shared/qtcreator.py @@ -34,7 +34,10 @@ import subprocess; import sys import errno; from datetime import datetime,timedelta; -import __builtin__ +try: + import __builtin__ # Python 2 +except ImportError: + import builtins as __builtin__ # Python 3 srcPath = '' SettingsPath = [] @@ -120,7 +123,7 @@ def waitForCleanShutdown(timeOut=10): while not shutdownDone: try: os.kill(appCtxt.pid,0) - except OSError, err: + except OSError as err: if err.errno == errno.EPERM or err.errno == errno.ESRCH: shutdownDone=True if not shutdownDone and datetime.utcnow() > endtime: @@ -208,7 +211,7 @@ def substituteCdb(settingsDir): try: serverIni = readFile(os.path.join(os.getenv("APPDATA"), "froglogic", "Squish", "ver1", "server.ini")) - autLine = filter(lambda line: "AUT/qtcreator" in line, serverIni.splitlines())[0] + autLine = list(filter(lambda line: "AUT/qtcreator" in line, serverIni.splitlines()))[0] autPath = autLine.split("\"")[1] return os.path.exists(os.path.join(autPath, "..", "lib", "qtcreatorcdbext64")) except: diff --git a/tests/system/shared/suites_qtta.py b/tests/system/shared/suites_qtta.py index f70b3cb1036..64a31e6a9a4 100755 --- a/tests/system/shared/suites_qtta.py +++ b/tests/system/shared/suites_qtta.py @@ -23,8 +23,6 @@ # ############################################################################ -import __builtin__ - # appends to line, by typing after text into widget def appendToLine(codeArea, insertAfterLine, typeWhat): if not placeCursorToLine(codeArea, insertAfterLine): diff --git a/tests/system/shared/workarounds.py b/tests/system/shared/workarounds.py index ab8e338ad7f..f0421220fbc 100644 --- a/tests/system/shared/workarounds.py +++ b/tests/system/shared/workarounds.py @@ -23,7 +23,10 @@ # ############################################################################ -import urllib2 +try: + from urllib2 import ProxyHandler, build_opener, install_opener, urlopen # Python 2 +except ImportError: + from urllib.request import ProxyHandler, build_opener, install_opener, urlopen # Python 3 ################ workarounds for issues tracked inside jira ################# @@ -43,7 +46,7 @@ class JIRA: def __init__(self, number, bugType=Bug.CREATOR): if JIRA.__instance__ == None: JIRA.__instance__ = JIRA.__impl(number, bugType) - JIRA.__dict__['_JIRA__instance__'] = JIRA.__instance__ + setattr(JIRA, '__instance__', JIRA.__instance__) else: JIRA.__instance__._bugType = bugType JIRA.__instance__._number = number @@ -102,10 +105,10 @@ class JIRA: proxy = os.getenv("SYSTEST_PROXY", None) try: if proxy: - proxy = urllib2.ProxyHandler({'https': proxy}) - opener = urllib2.build_opener(proxy) - urllib2.install_opener(opener) - bugReport = urllib2.urlopen('%s/%s' % (JIRA_URL, bug)) + proxy = ProxyHandler({'https': proxy}) + opener = build_opener(proxy) + install_opener(opener) + bugReport = urlopen('%s/%s' % (JIRA_URL, bug)) data = bugReport.read() except: data = self.__tryExternalTools__(proxy) @@ -118,6 +121,8 @@ class JIRA: test.fatal("No resolution info for %s" % bug) self._resolution = 'Done' else: + if isinstance(data, (bytes)): + data = str(data) data = data.replace("\r", "").replace("\n", "") resPattern = re.compile('(?P.*?)') resolution = resPattern.search(data) diff --git a/tests/system/suite_editors/tst_revert_changes/test.py b/tests/system/suite_editors/tst_revert_changes/test.py index d6e65b482cd..c4a7ade71fb 100644 --- a/tests/system/suite_editors/tst_revert_changes/test.py +++ b/tests/system/suite_editors/tst_revert_changes/test.py @@ -24,7 +24,6 @@ ############################################################################ source("../../shared/qtcreator.py") -import __builtin__ cppEditorStr = ":Qt Creator_CppEditor::Internal::CPPEditorWidget" originalSources = os.path.abspath(os.path.join(os.getcwd(), "..", "shared", "simplePlainCPP"))