eric6/PyUnit/UnittestDialog.py

changeset 8143
2c730d5fd177
parent 8029
5feb4f723f07
child 8149
3fefc0c430f2
equal deleted inserted replaced
8141:27f636beebad 8143:2c730d5fd177
41 @signal unittestStopped() emitted after a unit test was run 41 @signal unittestStopped() emitted after a unit test was run
42 """ 42 """
43 unittestFile = pyqtSignal(str, int, bool) 43 unittestFile = pyqtSignal(str, int, bool)
44 unittestStopped = pyqtSignal() 44 unittestStopped = pyqtSignal()
45 45
46 TestCaseNameRole = Qt.UserRole 46 TestCaseNameRole = Qt.ItemDataRole.UserRole
47 TestCaseFileRole = Qt.UserRole + 1 47 TestCaseFileRole = Qt.ItemDataRole.UserRole + 1
48 48
49 ErrorsInfoRole = Qt.UserRole 49 ErrorsInfoRole = Qt.ItemDataRole.UserRole
50 50
51 SkippedColorDarkTheme = QColor("#00aaff") 51 SkippedColorDarkTheme = QColor("#00aaff")
52 FailedExpectedColorDarkTheme = QColor("#ccaaff") 52 FailedExpectedColorDarkTheme = QColor("#ccaaff")
53 SucceededUnexpectedColorDarkTheme = QColor("#ff99dd") 53 SucceededUnexpectedColorDarkTheme = QColor("#ff99dd")
54 SkippedColorLightTheme = QColor("#0000ff") 54 SkippedColorLightTheme = QColor("#0000ff")
75 if name: 75 if name:
76 self.setObjectName(name) 76 self.setObjectName(name)
77 self.setupUi(self) 77 self.setupUi(self)
78 78
79 self.testsuitePicker.setMode(E5PathPickerModes.OpenFileMode) 79 self.testsuitePicker.setMode(E5PathPickerModes.OpenFileMode)
80 self.testsuitePicker.setInsertPolicy(QComboBox.InsertAtTop) 80 self.testsuitePicker.setInsertPolicy(
81 QComboBox.InsertPolicy.InsertAtTop)
81 self.testsuitePicker.setSizeAdjustPolicy( 82 self.testsuitePicker.setSizeAdjustPolicy(
82 QComboBox.AdjustToMinimumContentsLength) 83 QComboBox.SizeAdjustPolicy.AdjustToContents)
83 84
84 self.discoveryPicker.setMode(E5PathPickerModes.DirectoryMode) 85 self.discoveryPicker.setMode(E5PathPickerModes.DirectoryMode)
85 self.discoveryPicker.setInsertPolicy(QComboBox.InsertAtTop) 86 self.discoveryPicker.setInsertPolicy(
87 QComboBox.InsertPolicy.InsertAtTop)
86 self.discoveryPicker.setSizeAdjustPolicy( 88 self.discoveryPicker.setSizeAdjustPolicy(
87 QComboBox.AdjustToMinimumContentsLength) 89 QComboBox.SizeAdjustPolicy.AdjustToContents)
88 90
89 self.discoverButton = self.buttonBox.addButton( 91 self.discoverButton = self.buttonBox.addButton(
90 self.tr("Discover"), QDialogButtonBox.ActionRole) 92 self.tr("Discover"), QDialogButtonBox.ButtonRole.ActionRole)
91 self.discoverButton.setToolTip(self.tr( 93 self.discoverButton.setToolTip(self.tr(
92 "Discover tests")) 94 "Discover tests"))
93 self.discoverButton.setWhatsThis(self.tr( 95 self.discoverButton.setWhatsThis(self.tr(
94 """<b>Discover</b>""" 96 """<b>Discover</b>"""
95 """<p>This button starts a discovery of available tests.</p>""")) 97 """<p>This button starts a discovery of available tests.</p>"""))
96 self.startButton = self.buttonBox.addButton( 98 self.startButton = self.buttonBox.addButton(
97 self.tr("Start"), QDialogButtonBox.ActionRole) 99 self.tr("Start"), QDialogButtonBox.ButtonRole.ActionRole)
98 self.startButton.setToolTip(self.tr( 100 self.startButton.setToolTip(self.tr(
99 "Start the selected testsuite")) 101 "Start the selected testsuite"))
100 self.startButton.setWhatsThis(self.tr( 102 self.startButton.setWhatsThis(self.tr(
101 """<b>Start Test</b>""" 103 """<b>Start Test</b>"""
102 """<p>This button starts the selected testsuite.</p>""")) 104 """<p>This button starts the selected testsuite.</p>"""))
103 self.startFailedButton = self.buttonBox.addButton( 105 self.startFailedButton = self.buttonBox.addButton(
104 self.tr("Rerun Failed"), QDialogButtonBox.ActionRole) 106 self.tr("Rerun Failed"), QDialogButtonBox.ButtonRole.ActionRole)
105 self.startFailedButton.setToolTip( 107 self.startFailedButton.setToolTip(
106 self.tr("Reruns failed tests of the selected testsuite")) 108 self.tr("Reruns failed tests of the selected testsuite"))
107 self.startFailedButton.setWhatsThis(self.tr( 109 self.startFailedButton.setWhatsThis(self.tr(
108 """<b>Rerun Failed</b>""" 110 """<b>Rerun Failed</b>"""
109 """<p>This button reruns all failed tests of the selected""" 111 """<p>This button reruns all failed tests of the selected"""
110 """ testsuite.</p>""")) 112 """ testsuite.</p>"""))
111 self.stopButton = self.buttonBox.addButton( 113 self.stopButton = self.buttonBox.addButton(
112 self.tr("Stop"), QDialogButtonBox.ActionRole) 114 self.tr("Stop"), QDialogButtonBox.ButtonRole.ActionRole)
113 self.stopButton.setToolTip(self.tr("Stop the running unittest")) 115 self.stopButton.setToolTip(self.tr("Stop the running unittest"))
114 self.stopButton.setWhatsThis(self.tr( 116 self.stopButton.setWhatsThis(self.tr(
115 """<b>Stop Test</b>""" 117 """<b>Stop Test</b>"""
116 """<p>This button stops a running unittest.</p>""")) 118 """<p>This button stops a running unittest.</p>"""))
117 self.discoverButton.setEnabled(False) 119 self.discoverButton.setEnabled(False)
122 self.__dbs = dbs 124 self.__dbs = dbs
123 self.__forProject = False 125 self.__forProject = False
124 126
125 self.setWindowFlags( 127 self.setWindowFlags(
126 self.windowFlags() | Qt.WindowFlags( 128 self.windowFlags() | Qt.WindowFlags(
127 Qt.WindowContextHelpButtonHint)) 129 Qt.WindowType.WindowContextHelpButtonHint))
128 self.setWindowIcon(UI.PixmapCache.getIcon("eric")) 130 self.setWindowIcon(UI.PixmapCache.getIcon("eric"))
129 self.setWindowTitle(self.tr("Unittest")) 131 self.setWindowTitle(self.tr("Unittest"))
130 if dbs: 132 if dbs:
131 self.ui = ui 133 self.ui = ui
132 134
192 """ 194 """
193 Protected slot to handle key press events. 195 Protected slot to handle key press events.
194 196
195 @param evt key press event to handle (QKeyEvent) 197 @param evt key press event to handle (QKeyEvent)
196 """ 198 """
197 if evt.key() == Qt.Key_Escape and self.__dbs: 199 if evt.key() == Qt.Key.Key_Escape and self.__dbs:
198 self.close() 200 self.close()
199 201
200 def __populateVenvComboBox(self): 202 def __populateVenvComboBox(self):
201 """ 203 """
202 Private method to (re-)populate the virtual environments selector. 204 Private method to (re-)populate the virtual environments selector.
547 [testPath[index - 1]]) 549 [testPath[index - 1]])
548 else: 550 else:
549 itm = QTreeWidgetItem(pitm, 551 itm = QTreeWidgetItem(pitm,
550 [testPath[index - 1]]) 552 [testPath[index - 1]])
551 pitm.setExpanded(True) 553 pitm.setExpanded(True)
552 itm.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) 554 itm.setFlags(Qt.ItemFlag.ItemIsUserCheckable |
553 itm.setCheckState(0, Qt.Unchecked) 555 Qt.ItemFlag.ItemIsEnabled)
556 itm.setCheckState(0, Qt.CheckState.Unchecked)
554 itm.setData(0, UnittestDialog.TestCaseNameRole, modulePath) 557 itm.setData(0, UnittestDialog.TestCaseNameRole, modulePath)
555 if ( 558 if (
556 os.path.splitext(os.path.basename(filename))[0] == 559 os.path.splitext(os.path.basename(filename))[0] ==
557 itm.text(0) 560 itm.text(0)
558 ): 561 ):
576 selectedTests = [] 579 selectedTests = []
577 if parent is None: 580 if parent is None:
578 # top level 581 # top level
579 for index in range(self.discoveryList.topLevelItemCount()): 582 for index in range(self.discoveryList.topLevelItemCount()):
580 itm = self.discoveryList.topLevelItem(index) 583 itm = self.discoveryList.topLevelItem(index)
581 if itm.checkState(0) == Qt.Checked: 584 if itm.checkState(0) == Qt.CheckState.Checked:
582 selectedTests.append( 585 selectedTests.append(
583 itm.data(0, UnittestDialog.TestCaseNameRole)) 586 itm.data(0, UnittestDialog.TestCaseNameRole))
584 # ignore children because they are included implicitly 587 # ignore children because they are included implicitly
585 elif itm.childCount(): 588 elif itm.childCount():
586 # recursively check children 589 # recursively check children
588 591
589 else: 592 else:
590 # parent item with children 593 # parent item with children
591 for index in range(parent.childCount()): 594 for index in range(parent.childCount()):
592 itm = parent.child(index) 595 itm = parent.child(index)
593 if itm.checkState(0) == Qt.Checked: 596 if itm.checkState(0) == Qt.CheckState.Checked:
594 selectedTests.append( 597 selectedTests.append(
595 itm.data(0, UnittestDialog.TestCaseNameRole)) 598 itm.data(0, UnittestDialog.TestCaseNameRole))
596 # ignore children because they are included implicitly 599 # ignore children because they are included implicitly
597 elif itm.childCount(): 600 elif itm.childCount():
598 # recursively check children 601 # recursively check children
935 if text: 938 if text:
936 for pattern in self.rxPatterns: 939 for pattern in self.rxPatterns:
937 text = re.sub(pattern, "", text) 940 text = re.sub(pattern, "", text)
938 941
939 foundItems = self.testsListWidget.findItems( 942 foundItems = self.testsListWidget.findItems(
940 text, Qt.MatchFlags(Qt.MatchExactly)) 943 text, Qt.MatchFlags(Qt.MatchFlag.MatchExactly))
941 if len(foundItems) > 0: 944 if len(foundItems) > 0:
942 itm = foundItems[0] 945 itm = foundItems[0]
943 self.testsListWidget.setCurrentItem(itm) 946 self.testsListWidget.setCurrentItem(itm)
944 self.testsListWidget.scrollToItem(itm) 947 self.testsListWidget.scrollToItem(itm)
945 948
1154 ui = Ui_UnittestStacktraceDialog() 1157 ui = Ui_UnittestStacktraceDialog()
1155 ui.setupUi(self.dlg) 1158 ui.setupUi(self.dlg)
1156 self.dlg.traceback = ui.traceback 1159 self.dlg.traceback = ui.traceback
1157 1160
1158 ui.showButton = ui.buttonBox.addButton( 1161 ui.showButton = ui.buttonBox.addButton(
1159 self.tr("Show Source"), QDialogButtonBox.ActionRole) 1162 self.tr("Show Source"), QDialogButtonBox.ButtonRole.ActionRole)
1160 ui.showButton.clicked.connect(self.__showSource) 1163 ui.showButton.clicked.connect(self.__showSource)
1161 1164
1162 ui.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 1165 ui.buttonBox.button(
1166 QDialogButtonBox.StandardButton.Close).setDefault(True)
1163 1167
1164 self.dlg.setWindowTitle(text) 1168 self.dlg.setWindowTitle(text)
1165 ui.testLabel.setText(test) 1169 ui.testLabel.setText(test)
1166 ui.traceback.setPlainText(tracebackText) 1170 ui.traceback.setPlainText(tracebackText)
1167 1171
1353 1357
1354 @param obj reference to the object the event is meant for (QObject) 1358 @param obj reference to the object the event is meant for (QObject)
1355 @param event reference to the event object (QEvent) 1359 @param event reference to the event object (QEvent)
1356 @return flag indicating, whether the event was handled (boolean) 1360 @return flag indicating, whether the event was handled (boolean)
1357 """ 1361 """
1358 if event.type() == QEvent.Close: 1362 if event.type() == QEvent.Type.Close:
1359 QApplication.exit() 1363 QApplication.exit()
1360 return True 1364 return True
1361 1365
1362 return False 1366 return False

eric ide

mercurial