eric6/PyUnit/UnittestDialog.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8176
31965986ecd1
parent 8240
93b8a353c4bf
child 8400
b3eefd7e58d1
equal deleted inserted replaced
8190:fb0ef164f536 8273:698ae46f40a4
10 import unittest 10 import unittest
11 import sys 11 import sys
12 import time 12 import time
13 import re 13 import re
14 import os 14 import os
15 import contextlib
15 16
16 from PyQt5.QtCore import pyqtSignal, QEvent, Qt, pyqtSlot 17 from PyQt5.QtCore import pyqtSignal, QEvent, Qt, pyqtSlot
17 from PyQt5.QtGui import QColor 18 from PyQt5.QtGui import QColor
18 from PyQt5.QtWidgets import ( 19 from PyQt5.QtWidgets import (
19 QWidget, QDialog, QApplication, QDialogButtonBox, QListWidgetItem, 20 QWidget, QDialog, QApplication, QDialogButtonBox, QListWidgetItem,
69 @param parent parent widget of this dialog 70 @param parent parent widget of this dialog
70 @type QWidget 71 @type QWidget
71 @param name name of this dialog 72 @param name name of this dialog
72 @type str 73 @type str
73 """ 74 """
74 super(UnittestDialog, self).__init__(parent) 75 super().__init__(parent)
75 if name: 76 if name:
76 self.setObjectName(name) 77 self.setObjectName(name)
77 self.setupUi(self) 78 self.setupUi(self)
78 79
79 self.testsuitePicker.setMode(E5PathPickerModes.OpenFileMode) 80 self.testsuitePicker.setMode(E5PathPickerModes.OpenFileMode)
1228 @type QCloseEvent 1229 @type QCloseEvent
1229 """ 1230 """
1230 event.accept() 1231 event.accept()
1231 1232
1232 for editor in self.__editors: 1233 for editor in self.__editors:
1233 try: 1234 with contextlib.suppress(Exception):
1234 editor.close() 1235 editor.close()
1235 except Exception: # secok
1236 # ignore all exceptions
1237 pass
1238 1236
1239 1237
1240 class QtTestResult(unittest.TestResult): 1238 class QtTestResult(unittest.TestResult):
1241 """ 1239 """
1242 A TestResult derivative to work with a graphical GUI. 1240 A TestResult derivative to work with a graphical GUI.
1250 @param parent reference to the parent widget 1248 @param parent reference to the parent widget
1251 @type UnittestDialog 1249 @type UnittestDialog
1252 @param failfast flag indicating to stop at the first error 1250 @param failfast flag indicating to stop at the first error
1253 @type bool 1251 @type bool
1254 """ 1252 """
1255 super(QtTestResult, self).__init__() 1253 super().__init__()
1256 self.parent = parent 1254 self.parent = parent
1257 self.failfast = failfast 1255 self.failfast = failfast
1258 1256
1259 def addFailure(self, test, err): 1257 def addFailure(self, test, err):
1260 """ 1258 """
1261 Public method called if a test failed. 1259 Public method called if a test failed.
1262 1260
1263 @param test reference to the test object 1261 @param test reference to the test object
1264 @param err error traceback 1262 @param err error traceback
1265 """ 1263 """
1266 super(QtTestResult, self).addFailure(test, err) 1264 super().addFailure(test, err)
1267 tracebackLines = self._exc_info_to_string(err, test) 1265 tracebackLines = self._exc_info_to_string(err, test)
1268 self.parent.testFailed(str(test), tracebackLines, test.id()) 1266 self.parent.testFailed(str(test), tracebackLines, test.id())
1269 1267
1270 def addError(self, test, err): 1268 def addError(self, test, err):
1271 """ 1269 """
1272 Public method called if a test errored. 1270 Public method called if a test errored.
1273 1271
1274 @param test reference to the test object 1272 @param test reference to the test object
1275 @param err error traceback 1273 @param err error traceback
1276 """ 1274 """
1277 super(QtTestResult, self).addError(test, err) 1275 super().addError(test, err)
1278 tracebackLines = self._exc_info_to_string(err, test) 1276 tracebackLines = self._exc_info_to_string(err, test)
1279 self.parent.testErrored(str(test), tracebackLines, test.id()) 1277 self.parent.testErrored(str(test), tracebackLines, test.id())
1280 1278
1281 def addSkip(self, test, reason): 1279 def addSkip(self, test, reason):
1282 """ 1280 """
1283 Public method called if a test was skipped. 1281 Public method called if a test was skipped.
1284 1282
1285 @param test reference to the test object 1283 @param test reference to the test object
1286 @param reason reason for skipping the test (string) 1284 @param reason reason for skipping the test (string)
1287 """ 1285 """
1288 super(QtTestResult, self).addSkip(test, reason) 1286 super().addSkip(test, reason)
1289 self.parent.testSkipped(str(test), reason, test.id()) 1287 self.parent.testSkipped(str(test), reason, test.id())
1290 1288
1291 def addExpectedFailure(self, test, err): 1289 def addExpectedFailure(self, test, err):
1292 """ 1290 """
1293 Public method called if a test failed expected. 1291 Public method called if a test failed expected.
1294 1292
1295 @param test reference to the test object 1293 @param test reference to the test object
1296 @param err error traceback 1294 @param err error traceback
1297 """ 1295 """
1298 super(QtTestResult, self).addExpectedFailure(test, err) 1296 super().addExpectedFailure(test, err)
1299 tracebackLines = self._exc_info_to_string(err, test) 1297 tracebackLines = self._exc_info_to_string(err, test)
1300 self.parent.testFailedExpected(str(test), tracebackLines, test.id()) 1298 self.parent.testFailedExpected(str(test), tracebackLines, test.id())
1301 1299
1302 def addUnexpectedSuccess(self, test): 1300 def addUnexpectedSuccess(self, test):
1303 """ 1301 """
1304 Public method called if a test succeeded expectedly. 1302 Public method called if a test succeeded expectedly.
1305 1303
1306 @param test reference to the test object 1304 @param test reference to the test object
1307 """ 1305 """
1308 super(QtTestResult, self).addUnexpectedSuccess(test) 1306 super().addUnexpectedSuccess(test)
1309 self.parent.testSucceededUnexpected(str(test), test.id()) 1307 self.parent.testSucceededUnexpected(str(test), test.id())
1310 1308
1311 def startTest(self, test): 1309 def startTest(self, test):
1312 """ 1310 """
1313 Public method called at the start of a test. 1311 Public method called at the start of a test.
1314 1312
1315 @param test Reference to the test object 1313 @param test Reference to the test object
1316 """ 1314 """
1317 super(QtTestResult, self).startTest(test) 1315 super().startTest(test)
1318 self.parent.testStarted(str(test), test.shortDescription()) 1316 self.parent.testStarted(str(test), test.shortDescription())
1319 1317
1320 def stopTest(self, test): 1318 def stopTest(self, test):
1321 """ 1319 """
1322 Public method called at the end of a test. 1320 Public method called at the end of a test.
1323 1321
1324 @param test Reference to the test object 1322 @param test Reference to the test object
1325 """ 1323 """
1326 super(QtTestResult, self).stopTest(test) 1324 super().stopTest(test)
1327 self.parent.testFinished() 1325 self.parent.testFinished()
1328 1326
1329 1327
1330 class UnittestWindow(E5MainWindow): 1328 class UnittestWindow(E5MainWindow):
1331 """ 1329 """
1336 Constructor 1334 Constructor
1337 1335
1338 @param prog filename of the program to open 1336 @param prog filename of the program to open
1339 @param parent reference to the parent widget (QWidget) 1337 @param parent reference to the parent widget (QWidget)
1340 """ 1338 """
1341 super(UnittestWindow, self).__init__(parent) 1339 super().__init__(parent)
1342 self.cw = UnittestDialog(prog, parent=self) 1340 self.cw = UnittestDialog(prog, parent=self)
1343 self.cw.installEventFilter(self) 1341 self.cw.installEventFilter(self)
1344 size = self.cw.size() 1342 size = self.cw.size()
1345 self.setCentralWidget(self.cw) 1343 self.setCentralWidget(self.cw)
1346 self.resize(size) 1344 self.resize(size)

eric ide

mercurial