Optimized the testing widget code in order to speed up the display of test results (see issue 500). eric7

Sat, 06 May 2023 15:15:27 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 06 May 2023 15:15:27 +0200
branch
eric7
changeset 10020
3f2e1d0ef4e2
parent 10019
e56089d00750
child 10021
a71f50b3a503
child 10023
a842dbf8c0df

Optimized the testing widget code in order to speed up the display of test results (see issue 500).

src/eric7/Testing/TestResultsTree.py file | annotate | diff | comparison | revisions
src/eric7/Testing/TestingWidget.py file | annotate | diff | comparison | revisions
--- a/src/eric7/Testing/TestResultsTree.py	Fri May 05 18:16:57 2023 +0200
+++ b/src/eric7/Testing/TestResultsTree.py	Sat May 06 15:15:27 2023 +0200
@@ -84,6 +84,7 @@
             }
 
         self.__testResults = []
+        self.__testResultsById = {}
 
     def index(self, row, column, parent=QModelIndex()):
         """
@@ -250,6 +251,7 @@
         """
         self.beginResetModel()
         self.__testResults.clear()
+        self.__testResultsById.clear()
         self.endResetModel()
 
         self.summary.emit("")
@@ -307,6 +309,9 @@
         """
         self.beginResetModel()
         self.__testResults = copy.deepcopy(testResults)
+        self.__testResultsById.clear()
+        for testResult in testResults:
+            self.__testResultsById[testResult.id] = testResult
         self.endResetModel()
 
         self.summary.emit(self.__summary())
@@ -323,6 +328,8 @@
         lastRow = firstRow + len(testResults) - 1
         self.beginInsertRows(QModelIndex(), firstRow, lastRow)
         self.__testResults.extend(testResults)
+        for testResult in testResults:
+            self.__testResultsById[testResult.id] = testResult
         self.endInsertRows()
 
         self.summary.emit(self.__summary())
@@ -340,17 +347,18 @@
         testResultsToBeAdded = []
 
         for testResult in testResults:
-            for index, currentResult in enumerate(self.__testResults):
-                if currentResult.id == testResult.id:
-                    self.__testResults[index] = testResult
-                    if minIndex is None:
-                        minIndex = index
-                        maxIndex = index
-                    else:
-                        minIndex = min(minIndex, index)
-                        maxIndex = max(maxIndex, index)
+            if testResult.id in self.__testResultsById:
+                result = self.__testResultsById[testResult.id]
+                index = self.__testResults.index(result)
+                self.__testResults[index] = testResult
+                self.__testResultsById[testResult.id] = testResult
+                if minIndex is None:
+                    minIndex = index
+                    maxIndex = index
+                else:
+                    minIndex = min(minIndex, index)
+                    maxIndex = max(maxIndex, index)
 
-                    break
             else:
                 # Test result with given id was not found.
                 # Just add it to the list (could be a sub test)
@@ -474,7 +482,6 @@
         """
         super().rowsInserted(parent, startRow, endRow)
 
-        self.resizeColumns()
         self.spanFirstColumn(startRow, endRow)
 
     def dataChanged(self, topLeft, bottomRight, roles=[]):
@@ -490,7 +497,6 @@
         """
         super().dataChanged(topLeft, bottomRight, roles)
 
-        self.resizeColumns()
         while topLeft.parent().isValid():
             topLeft = topLeft.parent()
         while bottomRight.parent().isValid():
--- a/src/eric7/Testing/TestingWidget.py	Fri May 05 18:16:57 2023 +0200
+++ b/src/eric7/Testing/TestingWidget.py	Sat May 06 15:15:27 2023 +0200
@@ -549,7 +549,7 @@
     @pyqtSlot()
     def __updateProgress(self):
         """
-        Private slot update the progress indicators.
+        Private slot to update the progress indicators.
         """
         self.progressCounterRunCount.setText(str(self.__runCount))
         self.progressCounterRemCount.setText(str(self.__totalCount - self.__runCount))
@@ -596,6 +596,8 @@
 
         self.progressGroupBox.hide()
 
+        self.__resultsTree.resizeColumns()
+
         self.__updateButtonBoxButtons()
 
         self.testRunStopped.emit()
@@ -931,6 +933,7 @@
             for id, name, desc in testNames
         ]
         self.__resultsModel.addTestResults(testResults)
+        self.__resultsTree.resizeColumns()
 
         self.__totalCount += len(testResults)
         self.__updateProgress()
@@ -969,6 +972,7 @@
 
         if testResults:
             self.__resultsModel.addTestResults(testResults)
+            self.__resultsTree.resizeColumns()
 
     @pyqtSlot(tuple)
     def __testStarted(self, test):

eric ide

mercurial