diff options
author | Robert Loehning <robert.loehning@digia.com> | 2012-10-25 12:59:03 +0200 |
---|---|---|
committer | Robert Loehning <robert.loehning@digia.com> | 2012-10-25 13:58:34 +0200 |
commit | 95af1cd4f870f4e63d3d63c54247fc36cbb0dc48 (patch) | |
tree | 6946f1fdc4f0adfbdf2cc6c2d0f10886894c4728 /tests | |
parent | e94642e8f0b0c99259a14a769fc0b19266fbae3c (diff) | |
download | qt-creator-95af1cd4f870f4e63d3d63c54247fc36cbb0dc48.tar.gz |
Squish: Added helper functions for views and models
Change-Id: Ic5dc4a5fe11ec5f693ef9f5ddf3abbefd689fd99
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/system/shared/build_utils.py | 2 | ||||
-rw-r--r-- | tests/system/shared/debugger.py | 3 | ||||
-rw-r--r-- | tests/system/shared/editor_utils.py | 6 | ||||
-rw-r--r-- | tests/system/shared/hook_utils.py | 11 | ||||
-rw-r--r-- | tests/system/shared/project.py | 2 | ||||
-rw-r--r-- | tests/system/shared/project_explorer.py | 8 | ||||
-rwxr-xr-x | tests/system/shared/suites_qtta.py | 6 | ||||
-rw-r--r-- | tests/system/shared/utils.py | 28 | ||||
-rw-r--r-- | tests/system/suite_QMLS/tst_QMLS01/test.py | 4 | ||||
-rw-r--r-- | tests/system/suite_QMLS/tst_QMLS03/test.py | 6 | ||||
-rw-r--r-- | tests/system/suite_general/tst_create_proj_wizard/test.py | 11 |
11 files changed, 41 insertions, 46 deletions
diff --git a/tests/system/shared/build_utils.py b/tests/system/shared/build_utils.py index 1d72345dc9..1f5f5f43f8 100644 --- a/tests/system/shared/build_utils.py +++ b/tests/system/shared/build_utils.py @@ -142,7 +142,7 @@ def iterateBuildConfigs(targetCount, currentTarget, filter = ""): model = waitForObject(":scrollArea.Edit build configuration:_QComboBox", 20000).model() prog = re.compile(filter) # for each row in the model, write its data to a list - configNames = [str(model.index(row, 0).data()) for row in range(model.rowCount())] + configNames = dumpItems(model) # pick only those configuration names which pass the filter configs = [config for config in configNames if prog.match(config)] switchViewTo(ViewConstants.EDIT) diff --git a/tests/system/shared/debugger.py b/tests/system/shared/debugger.py index 1472835b54..f58056cf90 100644 --- a/tests/system/shared/debugger.py +++ b/tests/system/shared/debugger.py @@ -89,8 +89,7 @@ def removeOldBreakpoints(): test.log("No breakpoints found...") else: test.log("Found %d breakpoints - removing them" % model.rowCount()) - for row in range(model.rowCount()): - currentIndex = model.index(row,0) + for currentIndex in dumpIndices(model): rect = breakPointTreeView.visualRect(currentIndex) mouseClick(breakPointTreeView, rect.x+5, rect.y+5, 0, Qt.LeftButton) type(breakPointTreeView, "<Delete>") diff --git a/tests/system/shared/editor_utils.py b/tests/system/shared/editor_utils.py index 25cc9d2c25..7f96fc189b 100644 --- a/tests/system/shared/editor_utils.py +++ b/tests/system/shared/editor_utils.py @@ -261,13 +261,11 @@ def validateSearchResult(expectedCount): matches = cast((str(counterLabel.text)).split(" ", 1)[0], "int") test.compare(matches, expectedCount, "Verified match count.") model = resultTreeView.model() - for row in range(model.rowCount()): - index = model.index(row, 0) + for index in dumpIndices(model): itemText = str(model.data(index).toString()) doubleClickItem(resultTreeView, maskSpecialCharsForSearchResult(itemText), 5, 5, 0, Qt.LeftButton) test.log("%d occurrences in %s" % (model.rowCount(index), itemText)) - for chRow in range(model.rowCount(index)): - chIndex = model.index(chRow, 0, index) + for chIndex in dumpIndices(model, index): resultTreeView.scrollTo(chIndex) text = str(chIndex.data()).rstrip('\r') rect = resultTreeView.visualRect(chIndex) diff --git a/tests/system/shared/hook_utils.py b/tests/system/shared/hook_utils.py index ced6286c62..9db0b84d26 100644 --- a/tests/system/shared/hook_utils.py +++ b/tests/system/shared/hook_utils.py @@ -25,9 +25,8 @@ def modifyRunSettingsForHookInto(projectName, port): envVarsTableView = waitForObject("{type='QTableView' visible='1' unnamed='1'}") model = envVarsTableView.model() changingVars = [] - for row in range(model.rowCount()): + for index in dumpIndices(model): # get var name - index = model.index(row, 0) envVarsTableView.scrollTo(index) varName = str(model.data(index).toString()) # if its a special SQUISH var simply unset it, SQUISH_LIBQTDIR and PATH will be replaced with Qt paths @@ -172,9 +171,7 @@ def getQMakeFromQtVersion(qtVersion): mouseClick(qtVersionTab, 5, 5, 0, Qt.LeftButton) qtVersionsTree = waitForObject("{name='qtdirList' type='QTreeWidget' visible='1'}") rootIndex = qtVersionsTree.invisibleRootItem() - rows = rootIndex.childCount() - for currentRow in range(rows): - current = rootIndex.child(currentRow) + for current in dumpChildren(rootIndex): child = getTreeWidgetChildByText(current, qtVersion) if child != None: break @@ -191,9 +188,7 @@ def getQMakeFromQtVersion(qtVersion): return qmake def getTreeWidgetChildByText(parent, text, column=0): - childCount = parent.childCount() - for row in range(childCount): - child = parent.child(row) + for child in dumpChildren(parent): if child.text(column)==text: return child return None diff --git a/tests/system/shared/project.py b/tests/system/shared/project.py index 28b54dcae9..264921eb3f 100644 --- a/tests/system/shared/project.py +++ b/tests/system/shared/project.py @@ -468,7 +468,7 @@ def __sortFilenamesOSDependent__(filenames): def __iterateChildren__(model, parent, nestingLevel=0): children = [] - for currentIndex in [model.index(row, 0, parent) for row in range(model.rowCount(parent))]: + for currentIndex in dumpIndices(model, parent): children.append([str(currentIndex.text), nestingLevel]) if model.hasChildren(currentIndex): children.extend(__iterateChildren__(model, currentIndex, nestingLevel + 1)) diff --git a/tests/system/shared/project_explorer.py b/tests/system/shared/project_explorer.py index b15cc868e5..7bbb426a4a 100644 --- a/tests/system/shared/project_explorer.py +++ b/tests/system/shared/project_explorer.py @@ -188,12 +188,12 @@ def __selectTreeItemOnBuildAndRun__(treeViewOrWidget, itemText, isRegex=False): pattern = re.compile(itemText) found = False for section in [autoDetected, manual]: - for index in [section.child(i, 0) for i in range(model.rowCount(section))]: - if (isRegex and pattern.match(str(index.data().toString())) - or itemText == (str(index.data().toString()))): + for dumpedItem in dumpItems(model, section): + if (isRegex and pattern.match(dumpedItem) + or itemText == dumpedItem): found = True item = ".".join([str(section.data().toString()), - str(index.data().toString()).replace(".", "\\.")]) + dumpedItem.replace(".", "\\.")]) clickItem(treeViewOrWidget, item, 5, 5, 0, Qt.LeftButton) break if found: diff --git a/tests/system/shared/suites_qtta.py b/tests/system/shared/suites_qtta.py index 73198748ce..452f1eef29 100755 --- a/tests/system/shared/suites_qtta.py +++ b/tests/system/shared/suites_qtta.py @@ -19,11 +19,9 @@ def checkSyntaxError(issuesView, expectedTextsArray, warnIfMoreIssues = True): if(warnIfMoreIssues and issuesModel.rowCount() > 1): test.warning("More than one expected issues reported") # iterate issues and check if there exists "Unexpected token" message - for row in range(issuesModel.rowCount()): + for description, type in zip(dumpItems(issuesModel, role=Qt.UserRole + 3), + dumpItems(issuesModel, role=Qt.UserRole + 5)): # enum Roles { File = Qt::UserRole, Line, MovedLine, Description, FileNotFound, Type, Category, Icon, Task_t }; - index = issuesModel.index(row, 0) - description = str(index.data(Qt.UserRole + 3).toString()) - type = str(index.data(Qt.UserRole + 5).toString()) # check if at least one of expected texts found in issue text for expectedText in expectedTextsArray: if expectedText in description: diff --git a/tests/system/shared/utils.py b/tests/system/shared/utils.py index 852fae0414..28f7795160 100644 --- a/tests/system/shared/utils.py +++ b/tests/system/shared/utils.py @@ -434,11 +434,9 @@ def iterateQtVersions(keepOptionsOpen=False, alreadyOnOptionsDialog=False, pattern = re.compile("Qt version (?P<version>.*?) for (?P<target>.*)") treeWidget = waitForObject(":QtSupport__Internal__QtVersionManager.qtdirList_QTreeWidget") root = treeWidget.invisibleRootItem() - for childRow in range(root.childCount()): - rootChild = root.child(childRow) + for rootChild in dumpChildren(root): rootChildText = str(rootChild.text(0)).replace(".", "\\.") - for row in range(rootChild.childCount()): - subChild = rootChild.child(row) + for subChild in dumpChildren(rootChild): subChildText = str(subChild.text(0)).replace(".", "\\.") clickItem(treeWidget, ".".join([rootChildText,subChildText]), 5, 5, 0, Qt.LeftButton) currentText = str(waitForObject(":QtSupport__Internal__QtVersionManager.QLabel").text) @@ -503,13 +501,13 @@ def iterateKits(keepOptionsOpen=False, alreadyOnOptionsDialog=False, manual = model.index(1, 0) test.compare(manual.data().toString(), "Manual", "Verifying label for target section") for section in [autoDetected, manual]: - for index in [section.child(i, 0) for i in range(model.rowCount(section))]: - kitName = str(index.data().toString()) + for currentItem in dumpItems(model, section): + kitName = currentItem if (kitName.endswith(" (default)")): kitName = kitName.rsplit(" (default)", 1)[0] result.append(kitName) item = ".".join([str(section.data().toString()), - str(index.data().toString()).replace(".", "\\.")]) + currentItem.replace(".", "\\.")]) if additionalFunction: try: if isinstance(additionalFunction, (str, unicode)): @@ -547,3 +545,19 @@ def removePackagingDirectory(projectPath): deleteDirIfExists(qtcPackaging) else: test.log("Couldn't remove packaging directory '%s' - did not exist." % qtcPackaging) + +# returns the indices from a QAbstractItemModel +def dumpIndices(model, parent=None, column=0): + if parent: + return [model.index(row, column, parent) for row in range(model.rowCount(parent))] + else: + return [model.index(row, column) for row in range(model.rowCount())] + +DisplayRole = 0 +# returns the data from a QAbstractItemModel as strings +def dumpItems(model, parent=None, role=DisplayRole, column=0): + return [str(index.data(role)) for index in dumpIndices(model, parent, column)] + +# returns the children of a QTreeWidgetItem +def dumpChildren(item): + return [item.child(index) for index in range(item.childCount())] diff --git a/tests/system/suite_QMLS/tst_QMLS01/test.py b/tests/system/suite_QMLS/tst_QMLS01/test.py index f7d26b9a6e..9fbec51e91 100644 --- a/tests/system/suite_QMLS/tst_QMLS01/test.py +++ b/tests/system/suite_QMLS/tst_QMLS01/test.py @@ -16,9 +16,7 @@ def __beginTestSuggestions__(editorArea, lineText, textToType): def verifySuggestions(textToType): popup = findObject(":popupFrame_Proposal_QListView") model = popup.model() - for row in range(model.rowCount()): - index = model.index(row, 0) - text = str(model.data(index).toString()) + for text in dumpItems(model): test.verify(textToType.lower() in text.lower(), "Checking whether suggestion '%s' makes sense for typed '%s'" % (text, textToType)) diff --git a/tests/system/suite_QMLS/tst_QMLS03/test.py b/tests/system/suite_QMLS/tst_QMLS03/test.py index 75d7a842e0..4340260f65 100644 --- a/tests/system/suite_QMLS/tst_QMLS03/test.py +++ b/tests/system/suite_QMLS/tst_QMLS03/test.py @@ -13,14 +13,12 @@ def checkUsages(resultsView, expectedResults): resultsModel = resultsView.model() waitFor("resultsModel.rowCount() > 0", 5000) expectedResultIndex = 0 - for row in range(resultsModel.rowCount()): + for index in dumpIndices(resultsModel): # enum Roles { ResultItemRole = Qt::UserRole, ResultLineRole, ResultLineNumberRole, ResultIconRole, # SearchTermStartRole, SearchTermLengthRole, IsGeneratedRole }; - index = resultsModel.index(row, 0) # get only filename not full path resultFile = str(index.data(Qt.UserRole + 1).toString()).replace("\\", "/").split('/')[-1] - for chRow in range(resultsModel.rowCount(index)): - chIndex = resultsModel.index(chRow, 0, index) + for chIndex in dumpIndices(resultsModel, index): resultLine = str(chIndex.data(Qt.UserRole + 1).toString()).strip() resultLineNumber = chIndex.data(Qt.UserRole + 2).toInt() # verify if we don't get more results 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 c044c9e778..8995d20344 100644 --- a/tests/system/suite_general/tst_create_proj_wizard/test.py +++ b/tests/system/suite_general/tst_create_proj_wizard/test.py @@ -24,20 +24,15 @@ def main(): comboBox = waitForObject("{name='comboBox' type='QComboBox' visible='1' " "window=':New_Core::Internal::NewDialog'}") test.compare(comboBox.currentText, "All Templates") - for row in range(catModel.rowCount(projects)): - index = catModel.index(row, 0, projects) - category = str(index.data()).replace(".", "\\.") + for category in [item.replace(".", "\\.") for item in dumpItems(catModel, projects)]: # skip non-configurable if "Import" in category or "Non-Qt" in category: continue clickItem(categoriesView, "Projects." + category, 5, 5, 0, Qt.LeftButton) templatesView = waitForObject("{name='templatesView' type='QListView' visible='1'}", 20000) # needed because categoriesView and templatesView using same model - tempRootIndex = templatesView.rootIndex() - tempModel = templatesView.model() - for tRow in range(tempModel.rowCount(tempRootIndex)): - tIndex = tempModel.index(tRow, 0, tempRootIndex) - template = str(tempModel.data(tIndex)).replace(".", "\\.") + for template in dumpItems(templatesView.model(), templatesView.rootIndex()): + template = template.replace(".", "\\.") # skip non-configurable if "Qt Quick UI" in template or "Plain C" in template: continue |