From a521114519833efce73afe7dab806cf81e15a27f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20L=C3=B6hning?= Date: Wed, 26 Jul 2023 17:30:53 +0200 Subject: [PATCH] SquishTests: Don't initialize an entire list for reading one item The point of Python3 returning objects instead of lists is that it will iterate just as far as items are actually being used. Change-Id: If4d9742bb47aa9cac1166a0ff6f10d211829fd85 Reviewed-by: Christian Stenger --- tests/system/shared/debugger.py | 4 ++-- tests/system/shared/qtcreator.py | 3 ++- tests/system/suite_HELP/tst_HELP02/test.py | 2 +- .../suite_general/tst_cmake_speedcrunch/test.py | 2 +- .../suite_general/tst_create_proj_wizard/test.py | 4 ++-- .../suite_general/tst_default_settings/test.py | 12 ++++++------ tests/system/suite_tools/tst_git_local/test.py | 4 ++-- 7 files changed, 16 insertions(+), 15 deletions(-) diff --git a/tests/system/shared/debugger.py b/tests/system/shared/debugger.py index 7176afc8e59..b878f9efef6 100644 --- a/tests/system/shared/debugger.py +++ b/tests/system/shared/debugger.py @@ -238,7 +238,7 @@ def __logDebugResult__(): def verifyBreakPoint(bpToVerify): if isinstance(bpToVerify, dict): - fileName = list(bpToVerify.keys())[0] + fileName = next(iter(bpToVerify.keys())) editor = getEditorForFileSuffix(fileName) if editor: test.compare(waitForObject(":DebugModeWidget_QComboBox").toolTip, fileName, @@ -247,7 +247,7 @@ def verifyBreakPoint(bpToVerify): windowTitle = str(waitForObject(":Qt Creator_Core::Internal::MainWindow").windowTitle) test.verify(windowTitle.startswith(os.path.basename(fileName) + " "), "Verify that Creator's window title changed according to current file") - return test.compare(line, list(bpToVerify.values())[0], + return test.compare(line, next(iter(bpToVerify.values())), "Compare hit breakpoint to expected line number in %s" % fileName) else: test.fatal("Expected a dict for bpToVerify - got '%s'" % className(bpToVerify)) diff --git a/tests/system/shared/qtcreator.py b/tests/system/shared/qtcreator.py index 0b86001529f..bb52497774b 100644 --- a/tests/system/shared/qtcreator.py +++ b/tests/system/shared/qtcreator.py @@ -206,7 +206,8 @@ def substituteCdb(settingsDir): try: serverIni = readFile(os.path.join(os.getenv("APPDATA"), "froglogic", "Squish", "ver1", "server.ini")) - autLine = list(filter(lambda line: "AUT/qtcreator" in line, serverIni.splitlines()))[0] + autLine = next(iter(filter(lambda line: "AUT/qtcreator" in line, + serverIni.splitlines()))) autPath = autLine.split("\"")[1] return os.path.exists(os.path.join(autPath, "..", "lib", "qtcreatorcdbext64")) except: diff --git a/tests/system/suite_HELP/tst_HELP02/test.py b/tests/system/suite_HELP/tst_HELP02/test.py index 8b6c32b7ded..9c5104087e0 100644 --- a/tests/system/suite_HELP/tst_HELP02/test.py +++ b/tests/system/suite_HELP/tst_HELP02/test.py @@ -44,7 +44,7 @@ def checkQtCreatorHelpVersion(expectedVersion): helpContentWidget = waitForObject(':Qt Creator_QHelpContentWidget', 5000) waitFor("any(map(rightStart, dumpItems(helpContentWidget.model())))", 10000) items = dumpItems(helpContentWidget.model()) - test.compare(list(filter(rightStart, items))[0], + test.compare(next(iter(filter(rightStart, items))), 'Qt Creator Manual %s' % expectedVersion, 'Verifying whether manual uses expected version.') except: diff --git a/tests/system/suite_general/tst_cmake_speedcrunch/test.py b/tests/system/suite_general/tst_cmake_speedcrunch/test.py index 681835818ed..4f75d43eb9d 100644 --- a/tests/system/suite_general/tst_cmake_speedcrunch/test.py +++ b/tests/system/suite_general/tst_cmake_speedcrunch/test.py @@ -9,7 +9,7 @@ def cmakeSupported(): versionLines = filter(lambda line: "cmake version " in line, getOutputFromCmdline(["cmake", "--version"]).splitlines()) try: - versionLine = list(versionLines)[0] + versionLine = next(iter(versionLines)) test.log("Using " + versionLine) matcher = re.match("cmake version (\d+)\.(\d+)\.\d+", versionLine) major = __builtin__.int(matcher.group(1)) diff --git a/tests/system/suite_general/tst_create_proj_wizard/test.py b/tests/system/suite_general/tst_create_proj_wizard/test.py index 8579111b02c..d521f2092dd 100644 --- a/tests/system/suite_general/tst_create_proj_wizard/test.py +++ b/tests/system/suite_general/tst_create_proj_wizard/test.py @@ -49,8 +49,8 @@ def main(): availableProjectTypes.append({category:template}) safeClickButton("Cancel") for current in availableProjectTypes: - category = list(current.keys())[0] - template = list(current.values())[0] + category = next(iter(current.keys())) + template = next(iter(current.values())) with TestSection("Testing project template %s -> %s" % (category, template)): displayedPlatforms = __createProject__(category, template) if template.startswith("Qt Quick Application"): diff --git a/tests/system/suite_general/tst_default_settings/test.py b/tests/system/suite_general/tst_default_settings/test.py index ce026e98d36..f7ece36e6de 100644 --- a/tests/system/suite_general/tst_default_settings/test.py +++ b/tests/system/suite_general/tst_default_settings/test.py @@ -311,15 +311,15 @@ def __compareCompilers__(foundCompilers, expectedCompilers): for currentExp in expectedCompilers: if isString(currentExp): continue - key = list(currentExp.keys())[0] + key = next(iter(currentExp.keys())) # the regex .*? is used for the different possible version strings of the WinSDK # if it's present a regex will be validated otherwise simple string comparison # same applies for [.0-9]+ which is used for minor/patch versions isRegex = ".*?" in key or "[.0-9]+" in key - if (((isRegex and re.match(key, list(currentFound.keys())[0], flags))) + if (((isRegex and re.match(key, next(iter(currentFound.keys())), flags))) or currentFound.keys() == currentExp.keys()): - if ((isWin and os.path.abspath(list(currentFound.values())[0].lower()) - == os.path.abspath(list(currentExp.values())[0].lower())) + if ((isWin and os.path.abspath(next(iter(currentFound.values())).lower()) + == os.path.abspath(next(iter(currentExp.values())).lower())) or currentFound.values() == currentExp.values()): foundExp = True break @@ -375,8 +375,8 @@ def __checkCreatedSettings__(settingsFolder): test.verify(os.path.isdir(f), "Verifying whether folder '%s' has been created." % os.path.basename(f)) for f in files: - fName = list(f.keys())[0] - fMinSize = list(f.values())[0] + fName = next(iter(f.keys())) + fMinSize = next(iter(f.values())) text = "created non-empty" if fMinSize > 0: text = "modified" diff --git a/tests/system/suite_tools/tst_git_local/test.py b/tests/system/suite_tools/tst_git_local/test.py index 9ce9a0b3164..450f3b58558 100644 --- a/tests/system/suite_tools/tst_git_local/test.py +++ b/tests/system/suite_tools/tst_git_local/test.py @@ -90,8 +90,8 @@ def __clickCommit__(count): {"Author: %s, %s" % (id, time): True}, {"Committer: %s, %s" % (id, time): True}] for line, exp in zip(show.splitlines(), expected): - expLine = list(exp.keys())[0] - isRegex = list(exp.values())[0] + expLine = next(iter(exp.keys())) + isRegex = next(iter(exp.values())) if isRegex: test.verify(re.match(expLine, line), "Verifying commit header line '%s'" % line) else: