src/eric7/Testing/TestResultsTree.py

Wed, 20 Dec 2023 11:06:38 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 20 Dec 2023 11:06:38 +0100
branch
eric7
changeset 10427
3733e2b23cf7
parent 10405
df7e1694d0eb
child 10431
64157aeb0312
permissions
-rw-r--r--

Testing
- Fixed a bug in the result list causing the "Show Source" context menu entry being enabled even when no such info was reported by the testing backend.

9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
9653
e67609152c5e Updated copyright for 2023.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9502
diff changeset
3 # Copyright (c) 2022 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a tree view and associated model to show the test result
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 data.
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9 """
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
11 import contextlib
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
12 import copy
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
13 import locale
9063
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
14
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
15 from collections import Counter
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
16 from operator import attrgetter
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
17
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 from PyQt6.QtCore import (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
19 QAbstractItemModel,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
20 QCoreApplication,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
21 QModelIndex,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
22 QPoint,
10404
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
23 QSortFilterProxyModel,
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
24 Qt,
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
25 pyqtSignal,
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
26 pyqtSlot,
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 )
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
28 from PyQt6.QtGui import QBrush, QColor
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
29 from PyQt6.QtWidgets import QMenu, QTreeView
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
31 from eric7 import Preferences
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
32 from eric7.EricWidgets.EricApplication import ericApp
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
33
9066
a219ade50f7c Performed some refactoring to avoid possible name clashes on case-insensitive systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9065
diff changeset
34 from .Interfaces.TestExecutorBase import TestResultCategory
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
35
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
36 TopLevelId = 2**32 - 1
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 class TestResultsModel(QAbstractItemModel):
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 Class implementing the item model containing the test data.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
42
9063
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
43 @signal summary(str) emitted whenever the model data changes. The element
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
44 is a summary of the test results of the model.
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
46
9063
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
47 summary = pyqtSignal(str)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
48
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 Headers = [
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 QCoreApplication.translate("TestResultsModel", "Status"),
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 QCoreApplication.translate("TestResultsModel", "Name"),
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 QCoreApplication.translate("TestResultsModel", "Message"),
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
53 QCoreApplication.translate("TestResultsModel", "Duration [ms]"),
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 ]
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
55
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
56 StatusColumn = 0
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
57 NameColumn = 1
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
58 MessageColumn = 2
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
59 DurationColumn = 3
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
60
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 def __init__(self, parent=None):
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 """
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
64
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 @param parent reference to the parent object (defaults to None)
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 @type QObject (optional)
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 """
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 super().__init__(parent)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
69
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
70 if ericApp().usesDarkPalette():
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
71 self.__backgroundColors = {
9066
a219ade50f7c Performed some refactoring to avoid possible name clashes on case-insensitive systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9065
diff changeset
72 TestResultCategory.RUNNING: None,
a219ade50f7c Performed some refactoring to avoid possible name clashes on case-insensitive systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9065
diff changeset
73 TestResultCategory.FAIL: QBrush(QColor("#880000")),
a219ade50f7c Performed some refactoring to avoid possible name clashes on case-insensitive systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9065
diff changeset
74 TestResultCategory.OK: QBrush(QColor("#005500")),
a219ade50f7c Performed some refactoring to avoid possible name clashes on case-insensitive systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9065
diff changeset
75 TestResultCategory.SKIP: QBrush(QColor("#3f3f3f")),
a219ade50f7c Performed some refactoring to avoid possible name clashes on case-insensitive systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9065
diff changeset
76 TestResultCategory.PENDING: QBrush(QColor("#004768")),
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
77 }
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
78 else:
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
79 self.__backgroundColors = {
9066
a219ade50f7c Performed some refactoring to avoid possible name clashes on case-insensitive systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9065
diff changeset
80 TestResultCategory.RUNNING: None,
a219ade50f7c Performed some refactoring to avoid possible name clashes on case-insensitive systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9065
diff changeset
81 TestResultCategory.FAIL: QBrush(QColor("#ff8080")),
a219ade50f7c Performed some refactoring to avoid possible name clashes on case-insensitive systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9065
diff changeset
82 TestResultCategory.OK: QBrush(QColor("#c1ffba")),
a219ade50f7c Performed some refactoring to avoid possible name clashes on case-insensitive systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9065
diff changeset
83 TestResultCategory.SKIP: QBrush(QColor("#c5c5c5")),
a219ade50f7c Performed some refactoring to avoid possible name clashes on case-insensitive systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9065
diff changeset
84 TestResultCategory.PENDING: QBrush(QColor("#6fbaff")),
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
85 }
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
86
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 self.__testResults = []
10020
3f2e1d0ef4e2 Optimized the testing widget code in order to speed up the display of test results (see issue 500).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
88 self.__testResultsById = {}
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
89
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
90 def index(self, row, column, parent=QModelIndex()):
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
91 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
92 Public method to generate an index for the given row and column to
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
93 identify the item.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
94
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
95 @param row row for the index
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
96 @type int
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
97 @param column column for the index
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
98 @type int
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
99 @param parent index of the parent item (defaults to QModelIndex())
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
100 @type QModelIndex (optional)
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
101 @return index for the item
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
102 @rtype QModelIndex
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
103 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
104 if not self.hasIndex(row, column, parent): # check bounds etc.
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
105 return QModelIndex()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
106
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
107 if not parent.isValid():
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
108 # top level item
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
109 return self.createIndex(row, column, TopLevelId)
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
110 else:
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
111 testResultIndex = parent.row()
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
112 return self.createIndex(row, column, testResultIndex)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
113
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
114 def data(self, index, role):
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
115 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
116 Public method to get the data for the various columns and roles.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
117
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
118 @param index index of the data to be returned
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
119 @type QModelIndex
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
120 @param role role designating the data to return
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
121 @type Qt.ItemDataRole
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
122 @return requested data item
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
123 @rtype Any
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
124 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
125 if not index.isValid():
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
126 return None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
127
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
128 row = index.row()
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
129 column = index.column()
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
130 idx = index.internalId()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
131
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
132 if role == Qt.ItemDataRole.DisplayRole:
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
133 if idx != TopLevelId:
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
134 if bool(self.__testResults[idx].extra):
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
135 return self.__testResults[idx].extra[index.row()]
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
136 else:
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
137 return None
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
138 elif column == TestResultsModel.StatusColumn:
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
139 return self.__testResults[row].status
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
140 elif column == TestResultsModel.NameColumn:
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
141 return self.__testResults[row].name
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
142 elif column == TestResultsModel.MessageColumn:
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
143 return self.__testResults[row].message
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
144 elif column == TestResultsModel.DurationColumn:
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
145 duration = self.__testResults[row].duration
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
146 return (
9063
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
147 ""
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
148 if duration is None
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
149 else locale.format_string("%.2f", duration, grouping=True)
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
150 )
9500
5771348ded12 Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
151 elif (
5771348ded12 Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
152 role == Qt.ItemDataRole.ToolTipRole
5771348ded12 Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
153 and idx == TopLevelId
5771348ded12 Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
154 and column == TestResultsModel.NameColumn
5771348ded12 Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
155 ):
5771348ded12 Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
156 return self.__testResults[row].name
5771348ded12 Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
157 elif role == Qt.ItemDataRole.FontRole and idx != TopLevelId:
5771348ded12 Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
158 return Preferences.getEditorOtherFonts("MonospacedFont")
5771348ded12 Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
159 elif role == Qt.ItemDataRole.BackgroundRole and idx == TopLevelId:
5771348ded12 Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
160 testResult = self.__testResults[row]
5771348ded12 Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
161 with contextlib.suppress(KeyError):
5771348ded12 Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
162 return self.__backgroundColors[testResult.category]
5771348ded12 Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
163 elif (
5771348ded12 Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
164 role == Qt.ItemDataRole.TextAlignmentRole
9502
6091145e189e 'Blacked' the code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9500
diff changeset
165 and idx == TopLevelId
6091145e189e 'Blacked' the code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9500
diff changeset
166 and column == TestResultsModel.DurationColumn
9500
5771348ded12 Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
167 ):
5771348ded12 Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
168 return Qt.AlignmentFlag.AlignRight.value
5771348ded12 Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
169 elif role == Qt.ItemDataRole.UserRole and idx == TopLevelId:
5771348ded12 Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
170 testresult = self.__testResults[row]
5771348ded12 Corrected some code style issues and changed some suppressed code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
171 return (testresult.filename, testresult.lineno)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
172
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
173 return None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
174
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
175 def headerData(self, section, orientation, role=Qt.ItemDataRole.DisplayRole):
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 """
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 Public method to get the header string for the various sections.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
178
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 @param section section number
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 @type int
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 @param orientation orientation of the header
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 @type Qt.Orientation
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 @param role data role (defaults to Qt.ItemDataRole.DisplayRole)
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 @type Qt.ItemDataRole (optional)
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 @return header string of the section
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 @rtype str
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 """
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 if (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
189 orientation == Qt.Orientation.Horizontal
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
190 and role == Qt.ItemDataRole.DisplayRole
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 ):
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 return TestResultsModel.Headers[section]
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 else:
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 return None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
195
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
196 def parent(self, index):
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
197 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
198 Public method to get the parent of the item pointed to by index.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
199
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
200 @param index index of the item
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
201 @type QModelIndex
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
202 @return index of the parent item
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
203 @rtype QModelIndex
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
204 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
205 if not index.isValid():
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
206 return QModelIndex()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
207
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
208 idx = index.internalId()
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
209 if idx == TopLevelId:
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
210 return QModelIndex()
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
211 else:
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
212 return self.index(idx, 0)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
213
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 def rowCount(self, parent=QModelIndex()):
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 """
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 Public method to get the number of row for a given parent index.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
217
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 @param parent index of the parent item (defaults to QModelIndex())
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 @type QModelIndex (optional)
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 @return number of rows
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 @rtype int
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 """
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 if not parent.isValid():
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 return len(self.__testResults)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
225
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
226 if (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
227 parent.internalId() == TopLevelId
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
228 and parent.column() == 0
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
229 and self.__testResults[parent.row()].extra is not None
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
230 ):
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 return len(self.__testResults[parent.row()].extra)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
232
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 return 0
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 def columnCount(self, parent=QModelIndex()):
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 """
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 Public method to get the number of columns.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
238
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 @param parent index of the parent item (defaults to QModelIndex())
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 @type QModelIndex (optional)
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 @return number of columns
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 @rtype int
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 """
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 if not parent.isValid():
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 return len(TestResultsModel.Headers)
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 else:
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 return 1
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
248
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 def clear(self):
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 """
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 Public method to clear the model data.
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 """
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 self.beginResetModel()
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 self.__testResults.clear()
10020
3f2e1d0ef4e2 Optimized the testing widget code in order to speed up the display of test results (see issue 500).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
255 self.__testResultsById.clear()
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 self.endResetModel()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
257
9064
339bb8c8007d Implemented the "Rerun Failed" functionality for the new unit test interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9063
diff changeset
258 self.summary.emit("")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
259
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
260 def sort(self, column, order):
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
261 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
262 Public method to sort the model data by column in order.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
263
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
264 @param column sort column number
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
265 @type int
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
266 @param order sort order
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
267 @type Qt.SortOrder
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
268 """ # __IGNORE_WARNING_D234r__
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
269
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
270 def durationKey(result):
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
271 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
272 Function to generate a key for duration sorting
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
273
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
274 @param result result object
9066
a219ade50f7c Performed some refactoring to avoid possible name clashes on case-insensitive systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9065
diff changeset
275 @type TestResult
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
276 @return sort key
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
277 @rtype float
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
278 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
279 return result.duration or -1.0
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
280
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
281 self.beginResetModel()
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
282 reverse = order == Qt.SortOrder.DescendingOrder
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
283 if column == TestResultsModel.StatusColumn:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
284 self.__testResults.sort(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
285 key=attrgetter("category", "status"), reverse=reverse
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
286 )
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
287 elif column == TestResultsModel.NameColumn:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
288 self.__testResults.sort(key=attrgetter("name"), reverse=reverse)
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
289 elif column == TestResultsModel.MessageColumn:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
290 self.__testResults.sort(key=attrgetter("message"), reverse=reverse)
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
291 elif column == TestResultsModel.DurationColumn:
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
292 self.__testResults.sort(key=durationKey, reverse=reverse)
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
293 self.endResetModel()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
294
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
295 def getTestResults(self):
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
296 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
297 Public method to get the list of test results managed by the model.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
298
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
299 @return list of test results managed by the model
9066
a219ade50f7c Performed some refactoring to avoid possible name clashes on case-insensitive systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9065
diff changeset
300 @rtype list of TestResult
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
301 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
302 return copy.deepcopy(self.__testResults)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
303
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
304 def setTestResults(self, testResults):
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
305 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
306 Public method to set the list of test results of the model.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
307
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
308 @param testResults test results to be managed by the model
9066
a219ade50f7c Performed some refactoring to avoid possible name clashes on case-insensitive systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9065
diff changeset
309 @type list of TestResult
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
310 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
311 self.beginResetModel()
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
312 self.__testResults = copy.deepcopy(testResults)
10020
3f2e1d0ef4e2 Optimized the testing widget code in order to speed up the display of test results (see issue 500).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
313 self.__testResultsById.clear()
3f2e1d0ef4e2 Optimized the testing widget code in order to speed up the display of test results (see issue 500).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
314 for testResult in testResults:
3f2e1d0ef4e2 Optimized the testing widget code in order to speed up the display of test results (see issue 500).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
315 self.__testResultsById[testResult.id] = testResult
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
316 self.endResetModel()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
317
9063
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
318 self.summary.emit(self.__summary())
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
319
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
320 def addTestResults(self, testResults):
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
321 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
322 Public method to add test results to the ones already managed by the
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
323 model.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
324
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
325 @param testResults test results to be added to the model
9066
a219ade50f7c Performed some refactoring to avoid possible name clashes on case-insensitive systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9065
diff changeset
326 @type list of TestResult
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
327 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
328 firstRow = len(self.__testResults)
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
329 lastRow = firstRow + len(testResults) - 1
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
330 self.beginInsertRows(QModelIndex(), firstRow, lastRow)
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
331 self.__testResults.extend(testResults)
10020
3f2e1d0ef4e2 Optimized the testing widget code in order to speed up the display of test results (see issue 500).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
332 for testResult in testResults:
3f2e1d0ef4e2 Optimized the testing widget code in order to speed up the display of test results (see issue 500).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
333 self.__testResultsById[testResult.id] = testResult
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
334 self.endInsertRows()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
335
9063
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
336 self.summary.emit(self.__summary())
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
337
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
338 def updateTestResults(self, testResults):
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
339 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
340 Public method to update the data of managed test result items.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
341
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
342 @param testResults test results to be updated
9066
a219ade50f7c Performed some refactoring to avoid possible name clashes on case-insensitive systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9065
diff changeset
343 @type list of TestResult
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
344 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
345 minIndex = None
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
346 maxIndex = None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
347
9063
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
348 testResultsToBeAdded = []
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
349
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
350 for testResult in testResults:
10020
3f2e1d0ef4e2 Optimized the testing widget code in order to speed up the display of test results (see issue 500).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
351 if testResult.id in self.__testResultsById:
3f2e1d0ef4e2 Optimized the testing widget code in order to speed up the display of test results (see issue 500).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
352 result = self.__testResultsById[testResult.id]
3f2e1d0ef4e2 Optimized the testing widget code in order to speed up the display of test results (see issue 500).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
353 index = self.__testResults.index(result)
3f2e1d0ef4e2 Optimized the testing widget code in order to speed up the display of test results (see issue 500).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
354 self.__testResults[index] = testResult
3f2e1d0ef4e2 Optimized the testing widget code in order to speed up the display of test results (see issue 500).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
355 self.__testResultsById[testResult.id] = testResult
3f2e1d0ef4e2 Optimized the testing widget code in order to speed up the display of test results (see issue 500).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
356 if minIndex is None:
3f2e1d0ef4e2 Optimized the testing widget code in order to speed up the display of test results (see issue 500).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
357 minIndex = index
3f2e1d0ef4e2 Optimized the testing widget code in order to speed up the display of test results (see issue 500).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
358 maxIndex = index
3f2e1d0ef4e2 Optimized the testing widget code in order to speed up the display of test results (see issue 500).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
359 else:
3f2e1d0ef4e2 Optimized the testing widget code in order to speed up the display of test results (see issue 500).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
360 minIndex = min(minIndex, index)
3f2e1d0ef4e2 Optimized the testing widget code in order to speed up the display of test results (see issue 500).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
361 maxIndex = max(maxIndex, index)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
362
9063
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
363 else:
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
364 # Test result with given id was not found.
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
365 # Just add it to the list (could be a sub test)
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
366 testResultsToBeAdded.append(testResult)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
367
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
368 if minIndex is not None:
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
369 self.dataChanged.emit(
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
370 self.index(minIndex, 0),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
371 self.index(maxIndex, len(TestResultsModel.Headers) - 1),
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
372 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
373
9063
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
374 self.summary.emit(self.__summary())
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
375
9063
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
376 if testResultsToBeAdded:
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
377 self.addTestResults(testResultsToBeAdded)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
378
9064
339bb8c8007d Implemented the "Rerun Failed" functionality for the new unit test interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9063
diff changeset
379 def getFailedTests(self):
339bb8c8007d Implemented the "Rerun Failed" functionality for the new unit test interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9063
diff changeset
380 """
339bb8c8007d Implemented the "Rerun Failed" functionality for the new unit test interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9063
diff changeset
381 Public method to extract the test ids of all failed tests.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
382
9064
339bb8c8007d Implemented the "Rerun Failed" functionality for the new unit test interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9063
diff changeset
383 @return test ids of all failed tests
339bb8c8007d Implemented the "Rerun Failed" functionality for the new unit test interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9063
diff changeset
384 @rtype list of str
339bb8c8007d Implemented the "Rerun Failed" functionality for the new unit test interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9063
diff changeset
385 """
339bb8c8007d Implemented the "Rerun Failed" functionality for the new unit test interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9063
diff changeset
386 failedIds = [
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
387 res.id
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
388 for res in self.__testResults
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
389 if (res.category == TestResultCategory.FAIL and not res.subtestResult)
9064
339bb8c8007d Implemented the "Rerun Failed" functionality for the new unit test interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9063
diff changeset
390 ]
339bb8c8007d Implemented the "Rerun Failed" functionality for the new unit test interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9063
diff changeset
391 return failedIds
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
392
9063
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
393 def __summary(self):
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
394 """
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
395 Private method to generate a test results summary text.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
396
9063
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
397 @return test results summary text
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
398 @rtype str
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
399 """
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
400 if len(self.__testResults) == 0:
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
401 return self.tr("No results to show")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
402
9063
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
403 counts = Counter(res.category for res in self.__testResults)
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
404 if all(
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
405 counts[category] == 0
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
406 for category in (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
407 TestResultCategory.FAIL,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
408 TestResultCategory.OK,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
409 TestResultCategory.SKIP,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
410 )
9063
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
411 ):
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
412 return self.tr("Collected %n test(s)", "", len(self.__testResults))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
413
9063
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
414 return self.tr(
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
415 "%n test(s)/subtest(s) total, {0} failed, {1} passed,"
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
416 " {2} skipped, {3} pending",
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
417 "",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
418 len(self.__testResults),
9063
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
419 ).format(
9066
a219ade50f7c Performed some refactoring to avoid possible name clashes on case-insensitive systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9065
diff changeset
420 counts[TestResultCategory.FAIL],
a219ade50f7c Performed some refactoring to avoid possible name clashes on case-insensitive systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9065
diff changeset
421 counts[TestResultCategory.OK],
a219ade50f7c Performed some refactoring to avoid possible name clashes on case-insensitive systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9065
diff changeset
422 counts[TestResultCategory.SKIP],
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
423 counts[TestResultCategory.PENDING],
9063
f1d7dd7ae471 Corrected the code dealing with subtests.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9062
diff changeset
424 )
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
425
10404
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
426 def getStatusFilterList(self):
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
427 """
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
428 Public method to get a list of the unique test result status.
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
429
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
430 @return test result status
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
431 @rtype set of str
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
432 """
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
433 return {t.status for t in self.__testResults}
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
434
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
435
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
436 class TestResultsFilterModel(QSortFilterProxyModel):
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
437 """
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
438 Class implementing a filter model to filter the test results by status.
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
439 """
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
440
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
441 def __init__(self, parent=None):
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
442 """
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
443 Constructor
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
444
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
445 @param parent reference to the parent object (QObject)
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
446 """
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
447 super().__init__(parent)
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
448
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
449 self.__statusFilterString = ""
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
450
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
451 def filterAcceptsRow(self, sourceRow, sourceParent):
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
452 """
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
453 Public method to determine, if the row is acceptable.
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
454
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
455 @param sourceRow row number in the source model
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
456 @type int
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
457 @param sourceParent index of the source item
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
458 @type QModelIndex
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
459 @return flag indicating acceptance
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
460 @rtype bool
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
461 """
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
462 sm = self.sourceModel()
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
463 idx = sm.index(sourceRow, 0, sourceParent)
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
464 status = sm.data(idx, Qt.ItemDataRole.DisplayRole)
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
465 return (
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
466 sourceParent.isValid()
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
467 or self.__statusFilterString == ""
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
468 or status == self.__statusFilterString
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
469 )
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
470
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
471 def setStatusFilterString(self, filterString):
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
472 """
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
473 Public method to set the status filter string.
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
474
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
475 @param filterString status filter string
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
476 @type str
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
477 """
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
478 self.__statusFilterString = filterString
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
479 self.invalidateRowsFilter()
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
480
10405
df7e1694d0eb Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10404
diff changeset
481
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
482 class TestResultsTreeView(QTreeView):
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
483 """
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
484 Class implementing a tree view to show the test result data.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
485
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
486 @signal goto(str, int) emitted to go to the position given by file name
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
487 and line number
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
488 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
489
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
490 goto = pyqtSignal(str, int)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
491
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
492 def __init__(self, parent=None):
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
493 """
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
494 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
495
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
496 @param parent reference to the parent widget (defaults to None)
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
497 @type QWidget (optional)
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
498 """
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
499 super().__init__(parent)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
500
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
501 self.setItemsExpandable(True)
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
502 self.setExpandsOnDoubleClick(False)
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
503 self.setSortingEnabled(True)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
504
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
505 self.header().setDefaultAlignment(Qt.AlignmentFlag.AlignCenter)
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
506 self.header().setSortIndicatorShown(False)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
507
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
508 self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
509
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
510 # connect signals and slots
10404
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
511 self.activated.connect(self.__gotoTestDefinition)
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
512 self.customContextMenuRequested.connect(self.__showContextMenu)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
513
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
514 self.header().sortIndicatorChanged.connect(self.sortByColumn)
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
515 self.header().sortIndicatorChanged.connect(
10069
435cc5875135 Corrected and checked some code style issues (unused function arguments).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10020
diff changeset
516 lambda col, order: self.header().setSortIndicatorShown(True) # noqa: U100
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
517 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
518
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
519 def reset(self):
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
520 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
521 Public method to reset the internal state of the view.
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
522 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
523 super().reset()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
524
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
525 self.resizeColumns()
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
526 self.spanFirstColumn(0, self.model().rowCount() - 1)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
527
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
528 def rowsInserted(self, parent, startRow, endRow):
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
529 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
530 Public method called when rows are inserted.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
531
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
532 @param parent model index of the parent item
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
533 @type QModelIndex
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
534 @param startRow first row been inserted
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
535 @type int
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
536 @param endRow last row been inserted
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
537 @type int
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
538 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
539 super().rowsInserted(parent, startRow, endRow)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
540
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
541 self.spanFirstColumn(startRow, endRow)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
542
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
543 def dataChanged(self, topLeft, bottomRight, roles=[]):
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
544 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
545 Public method called when the model data has changed.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
546
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
547 @param topLeft index of the top left element
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
548 @type QModelIndex
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
549 @param bottomRight index of the bottom right element
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
550 @type QModelIndex
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
551 @param roles list of roles changed (defaults to [])
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
552 @type list of Qt.ItemDataRole (optional)
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
553 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
554 super().dataChanged(topLeft, bottomRight, roles)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
555
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
556 while topLeft.parent().isValid():
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
557 topLeft = topLeft.parent()
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
558 while bottomRight.parent().isValid():
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
559 bottomRight = bottomRight.parent()
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
560 self.spanFirstColumn(topLeft.row(), bottomRight.row())
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
561
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
562 def resizeColumns(self):
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
563 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
564 Public method to resize the columns to their contents.
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
565 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
566 for column in range(self.model().columnCount()):
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
567 self.resizeColumnToContents(column)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
568
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
569 def spanFirstColumn(self, startRow, endRow):
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
570 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
571 Public method to make the first column span the row for second level
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
572 items.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
573
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
574 These items contain the test results.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
575
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
576 @param startRow index of the first row to span
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
577 @type QModelIndex
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
578 @param endRow index of the last row (including) to span
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
579 @type QModelIndex
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
580 """
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
581 model = self.model()
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
582 for row in range(startRow, endRow + 1):
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
583 index = model.index(row, 0)
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
584 for i in range(model.rowCount(index)):
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
585 self.setFirstColumnSpanned(i, index, True)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
586
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
587 def __canonicalIndex(self, index):
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
588 """
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
589 Private method to create the canonical index for a given index.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
590
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
591 The canonical index is the index of the first column of the test
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
592 result entry (i.e. the top-level item). If the index is invalid,
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
593 None is returned.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
594
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
595 @param index index to determine the canonical index for
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
596 @type QModelIndex
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
597 @return index of the firt column of the associated top-level item index
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
598 @rtype QModelIndex
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
599 """
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
600 if not index.isValid():
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
601 return None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
602
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
603 while index.parent().isValid(): # find the top-level node
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
604 index = index.parent()
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
605 index = index.sibling(index.row(), 0) # go to first column
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
606 return index
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
607
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
608 @pyqtSlot(QModelIndex)
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
609 def __gotoTestDefinition(self, index):
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
610 """
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
611 Private slot to show the test definition.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
612
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
613 @param index index for the double-clicked item
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
614 @type QModelIndex
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
615 """
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
616 cindex = self.__canonicalIndex(index)
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
617 filename, lineno = self.model().data(cindex, Qt.ItemDataRole.UserRole)
10404
f7d9c31f0c38 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10069
diff changeset
618 if filename:
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
619 if lineno is None:
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
620 lineno = 1
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
621 self.goto.emit(filename, lineno)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
622
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
623 @pyqtSlot(QPoint)
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
624 def __showContextMenu(self, pos):
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
625 """
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
626 Private slot to show the context menu.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
627
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
628 @param pos relative position for the context menu
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
629 @type QPoint
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
630 """
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
631 index = self.indexAt(pos)
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
632 cindex = self.__canonicalIndex(index)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
633
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
634 contextMenu = (
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
635 self.__createContextMenu(cindex)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
636 if cindex
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
637 else self.__createBackgroundContextMenu()
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
638 )
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
639 contextMenu.exec(self.mapToGlobal(pos))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
640
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
641 def __createContextMenu(self, index):
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
642 """
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
643 Private method to create a context menu for the item pointed to by the
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
644 given index.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
645
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
646 @param index index of the item
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
647 @type QModelIndex
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
648 @return created context menu
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
649 @rtype QMenu
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
650 """
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
651 menu = QMenu(self)
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
652 if self.isExpanded(index):
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
653 menu.addAction(self.tr("Collapse"), lambda: self.collapse(index))
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
654 else:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
655 act = menu.addAction(self.tr("Expand"), lambda: self.expand(index))
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
656 act.setEnabled(self.model().hasChildren(index))
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
657 menu.addSeparator()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
658
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
659 act = menu.addAction(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
660 self.tr("Show Source"), lambda: self.__gotoTestDefinition(index)
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
661 )
10427
3733e2b23cf7 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10405
diff changeset
662 act.setEnabled(
3733e2b23cf7 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10405
diff changeset
663 self.model().data(index, Qt.ItemDataRole.UserRole)[0] is not None
3733e2b23cf7 Testing
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10405
diff changeset
664 )
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
665 menu.addSeparator()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
666
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
667 menu.addAction(self.tr("Collapse All"), self.collapseAll)
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
668 menu.addAction(self.tr("Expand All"), self.expandAll)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
669
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
670 return menu
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
671
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
672 def __createBackgroundContextMenu(self):
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
673 """
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
674 Private method to create a context menu for the background.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
675
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
676 @return created context menu
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
677 @rtype QMenu
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
678 """
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
679 menu = QMenu(self)
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
680 menu.addAction(self.tr("Collapse All"), self.collapseAll)
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
681 menu.addAction(self.tr("Expand All"), self.expandAll)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
682
9065
39405e6eba20 Integrated the new testing widget into the eric IDE (compared to as a standalone app) and implemented the 'Show Source' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9064
diff changeset
683 return menu
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
684
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
685
9059
e7fd342f8bfc Implemented the basic functionality of the new unit test framework.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
686 #
9062
7f27bf3b50c3 Implemented most of the 'unittest' executor and runner.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9059
diff changeset
687 # eflag: noqa = M821, M822

eric ide

mercurial