def _resetItem(self, item, applyToAllChildren=False): item.setText(1, "") if variantToPyValue(item.data(1, QtCore.Qt.UserRole)): item.setData(1, QtCore.Qt.UserRole, 0) if applyToAllChildren: for i in range(item.childCount()): self._resetItem(item.child(i), applyToAllChildren)
def onSingleTestStop(self, testId, endTime): _, testId = self._testManager.parseParameterizedTestId(testId) item = self._findItemById(testId) if item: startTime = variantToPyValue(item.data(1, QtCore.Qt.UserRole)) item.setData(1, QtCore.Qt.UserRole + 1, endTime) rep = "%.3f s" % (endTime - startTime) item.setText(1, rep)
def showResultOnItemByTestId(self, testId, state): _, testId = self._testManager.parseParameterizedTestId(testId) item = self._findItemById(testId) if item: # For parameterized test, some might succeed but others might failed, we make sure # we set failed for this situation. if state == constants.TEST_RESULT_SKIP or state > variantToPyValue( self._stateOfItem(item) ): self._setItemIconState(item, state)
def onSingleTestStart(self, testId, startTime): isParameterized, testId = self._testManager.parseParameterizedTestId(testId) item = self._findItemById(testId) if item: self.focusItem(item) self._setTestIconStateToAncestors(item, constants.TEST_RESULT_RUNNING) if not isParameterized or not variantToPyValue( item.data(1, QtCore.Qt.UserRole) ): item.setData(1, QtCore.Qt.UserRole, startTime) item.setText(1, "running...")
def _calculateAncestorItemStates(self, item, updatedIds): cId = self.testIdOfItem(item) if cId in updatedIds: return updatedIds.add(cId) stateToSet = constants.TEST_RESULT_NONE for i in range(item.childCount()): cState = variantToPyValue(item.child(i).data(0, QtCore.Qt.UserRole + 1)) stateToSet = max(stateToSet, cState) self._setItemIconState(item, stateToSet) if item is self._rootTestItem: return self._calculateAncestorItemStates(item.parent(), updatedIds)
def _onTestRunnerSwitched(self): act = self.sender() if not act: return runnerMode = variantToPyValue(act.data()) self._testManager.setRunnerMode(runnerMode) runner = self._testManager.getRunner() self._updateConfigButton(runner) self._uiStream.write( ">> Switch to unittest runner <b>{}</b>.<br>".format( runner.name())) self._onReloadUiButtonClicked() appsettings.get().saveSimpleConfig( constants.CONFIG_KEY_LAST_RUNNER_MODE, runnerMode) for act in self._testRunnerActions: self._updateLabelOfTestRunnerAct(act, runnerMode)
def _itemMatchs(self, item, keywords): state = variantToPyValue(item.data(0, QtCore.Qt.UserRole + 1)) stateMatch = False txtMatch = True lbl = self.testIdOfItem(item).lower() hasFilter = False for each in keywords: if not each.startswith(":"): if each not in lbl: return False if each.startswith(":"): hasFilter = True if not stateMatch: desiredState = constants.TEST_RESULT_NONE if each in constants.KEYWORD_TEST_STATES: desiredState = constants.KEYWORD_TEST_STATES[each] if desiredState < 0: stateMatch = state > 0 else: stateMatch = state == desiredState stateMatch = stateMatch or not hasFilter return stateMatch and txtMatch
def simpleConfigValue(self, key, defaultValue=None): value = self._qsettings().value(key, defaultValue) return variantToPyValue(value)
def _setSelectedItemsLevel(self): level = variantToPyValue(self.sender().data()) loggingutils.setLoggingLevel(level, *self.selectedTestIds())
def _stateOfItem(self, item): return variantToPyValue(item.data(0, QtCore.Qt.UserRole + 1))
def _categoryOfItem(self, item): return variantToPyValue(item.data(0, QtCore.Qt.UserRole))
def _updateLabelOfTestRunnerAct(self, act, currentMode): runnerMode = variantToPyValue(act.data()) runner = self._testManager.getRunnerByMode(runnerMode) suffix = " [actived]" if runnerMode == currentMode else "" lbl = runner.name() + suffix act.setText(lbl)