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 <christian.stenger@qt.io>
This commit is contained in:
Robert Löhning
2023-07-26 17:30:53 +02:00
parent 4a8c08a349
commit a521114519
7 changed files with 16 additions and 15 deletions

View File

@@ -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))

View File

@@ -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:

View File

@@ -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:

View File

@@ -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))

View File

@@ -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"):

View File

@@ -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"

View File

@@ -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: