PyUnit/UnittestDialog.py

branch
Py2 comp.
changeset 3484
645c12de6b0c
parent 3178
f25fc1364c88
parent 3345
071afe8be2a1
child 3591
2f2a4a76dd22
equal deleted inserted replaced
3456:96232974dcdb 3484:645c12de6b0c
60 super(UnittestDialog, self).__init__(parent) 60 super(UnittestDialog, self).__init__(parent)
61 if name: 61 if name:
62 self.setObjectName(name) 62 self.setObjectName(name)
63 self.setupUi(self) 63 self.setupUi(self)
64 64
65 self.fileDialogButton.setIcon(UI.PixmapCache.getIcon("open.png"))
66
65 self.startButton = self.buttonBox.addButton( 67 self.startButton = self.buttonBox.addButton(
66 self.trUtf8("Start"), QDialogButtonBox.ActionRole) 68 self.tr("Start"), QDialogButtonBox.ActionRole)
67 self.startButton.setToolTip(self.trUtf8( 69 self.startButton.setToolTip(self.tr(
68 "Start the selected testsuite")) 70 "Start the selected testsuite"))
69 self.startButton.setWhatsThis(self.trUtf8( 71 self.startButton.setWhatsThis(self.tr(
70 """<b>Start Test</b>""" 72 """<b>Start Test</b>"""
71 """<p>This button starts the selected testsuite.</p>""")) 73 """<p>This button starts the selected testsuite.</p>"""))
72 self.startFailedButton = self.buttonBox.addButton( 74 self.startFailedButton = self.buttonBox.addButton(
73 self.trUtf8("Rerun Failed"), QDialogButtonBox.ActionRole) 75 self.tr("Rerun Failed"), QDialogButtonBox.ActionRole)
74 self.startFailedButton.setToolTip( 76 self.startFailedButton.setToolTip(
75 self.trUtf8("Reruns failed tests of the selected testsuite")) 77 self.tr("Reruns failed tests of the selected testsuite"))
76 self.startFailedButton.setWhatsThis(self.trUtf8( 78 self.startFailedButton.setWhatsThis(self.tr(
77 """<b>Rerun Failed</b>""" 79 """<b>Rerun Failed</b>"""
78 """<p>This button reruns all failed tests of the selected""" 80 """<p>This button reruns all failed tests of the selected"""
79 """ testsuite.</p>""")) 81 """ testsuite.</p>"""))
80 self.stopButton = self.buttonBox.addButton( 82 self.stopButton = self.buttonBox.addButton(
81 self.trUtf8("Stop"), QDialogButtonBox.ActionRole) 83 self.tr("Stop"), QDialogButtonBox.ActionRole)
82 self.stopButton.setToolTip(self.trUtf8("Stop the running unittest")) 84 self.stopButton.setToolTip(self.tr("Stop the running unittest"))
83 self.stopButton.setWhatsThis(self.trUtf8( 85 self.stopButton.setWhatsThis(self.tr(
84 """<b>Stop Test</b>""" 86 """<b>Stop Test</b>"""
85 """<p>This button stops a running unittest.</p>""")) 87 """<p>This button stops a running unittest.</p>"""))
86 self.stopButton.setEnabled(False) 88 self.stopButton.setEnabled(False)
87 self.startButton.setDefault(True) 89 self.startButton.setDefault(True)
88 self.startFailedButton.setEnabled(False) 90 self.startFailedButton.setEnabled(False)
92 94
93 self.setWindowFlags( 95 self.setWindowFlags(
94 self.windowFlags() | Qt.WindowFlags( 96 self.windowFlags() | Qt.WindowFlags(
95 Qt.WindowContextHelpButtonHint)) 97 Qt.WindowContextHelpButtonHint))
96 self.setWindowIcon(UI.PixmapCache.getIcon("eric.png")) 98 self.setWindowIcon(UI.PixmapCache.getIcon("eric.png"))
97 self.setWindowTitle(self.trUtf8("Unittest")) 99 self.setWindowTitle(self.tr("Unittest"))
98 if dbs: 100 if dbs:
99 self.ui = ui 101 self.ui = ui
100 else: 102 else:
101 self.localCheckBox.hide() 103 self.localCheckBox.hide()
102 self.__setProgressColor("green") 104 self.__setProgressColor("green")
112 self.savedSysPath = sys.path 114 self.savedSysPath = sys.path
113 if prog: 115 if prog:
114 self.insertProg(prog) 116 self.insertProg(prog)
115 117
116 self.rxPatterns = [ 118 self.rxPatterns = [
117 self.trUtf8("^Failure: "), 119 self.tr("^Failure: "),
118 self.trUtf8("^Error: "), 120 self.tr("^Error: "),
119 ] 121 ]
120 122
121 self.__failedTests = [] 123 self.__failedTests = []
122 124
123 # now connect the debug server signals if called from the eric5 IDE 125 # now connect the debug server signals if called from the eric5 IDE
191 ' '.join(["*{0}".format(ext) 193 ' '.join(["*{0}".format(ext)
192 for ext in self.dbs.getExtensions('Python2')]) 194 for ext in self.dbs.getExtensions('Python2')])
193 py3Extensions = \ 195 py3Extensions = \
194 ' '.join(["*{0}".format(ext) 196 ' '.join(["*{0}".format(ext)
195 for ext in self.dbs.getExtensions('Python3')]) 197 for ext in self.dbs.getExtensions('Python3')])
196 filter = self.trUtf8( 198 filter = self.tr(
197 "Python3 Files ({1});;Python2 Files ({0});;All Files (*)")\ 199 "Python3 Files ({1});;Python2 Files ({0});;All Files (*)")\
198 .format(py2Extensions, py3Extensions) 200 .format(py2Extensions, py3Extensions)
199 else: 201 else:
200 filter = self.trUtf8("Python Files (*.py);;All Files (*)") 202 filter = self.tr("Python Files (*.py);;All Files (*)")
201 prog = E5FileDialog.getOpenFileName( 203 prog = E5FileDialog.getOpenFileName(
202 self, 204 self,
203 "", 205 "",
204 self.testsuiteComboBox.currentText(), 206 self.testsuiteComboBox.currentText(),
205 filter) 207 filter)
256 258
257 prog = self.testsuiteComboBox.currentText() 259 prog = self.testsuiteComboBox.currentText()
258 if not prog: 260 if not prog:
259 E5MessageBox.critical( 261 E5MessageBox.critical(
260 self, 262 self,
261 self.trUtf8("Unittest"), 263 self.tr("Unittest"),
262 self.trUtf8("You must enter a test suite file.")) 264 self.tr("You must enter a test suite file."))
263 return 265 return
264 266
265 # prepend the selected file to the testsuite combobox 267 # prepend the selected file to the testsuite combobox
266 self.insertProg(prog) 268 self.insertProg(prog)
267 self.sbLabel.setText(self.trUtf8("Preparing Testsuite")) 269 self.sbLabel.setText(self.tr("Preparing Testsuite"))
268 QApplication.processEvents() 270 QApplication.processEvents()
269 271
270 testFunctionName = self.testComboBox.currentText() 272 testFunctionName = self.testComboBox.currentText()
271 if testFunctionName: 273 if testFunctionName:
272 self.insertTestName(testFunctionName) 274 self.insertTestName(testFunctionName)
331 module) 333 module)
332 except: 334 except:
333 exc_type, exc_value, exc_tb = sys.exc_info() 335 exc_type, exc_value, exc_tb = sys.exc_info()
334 E5MessageBox.critical( 336 E5MessageBox.critical(
335 self, 337 self,
336 self.trUtf8("Unittest"), 338 self.tr("Unittest"),
337 self.trUtf8( 339 self.tr(
338 "<p>Unable to run test <b>{0}</b>.<br>" 340 "<p>Unable to run test <b>{0}</b>.<br>"
339 "{1}<br>{2}</p>") 341 "{1}<br>{2}</p>")
340 .format(self.testName, str(exc_type), 342 .format(self.testName, str(exc_type),
341 str(exc_value))) 343 str(exc_value)))
342 return 344 return
390 @param exc_value value of exception occured during preparation (string) 392 @param exc_value value of exception occured during preparation (string)
391 """ 393 """
392 if nrTests == 0: 394 if nrTests == 0:
393 E5MessageBox.critical( 395 E5MessageBox.critical(
394 self, 396 self,
395 self.trUtf8("Unittest"), 397 self.tr("Unittest"),
396 self.trUtf8( 398 self.tr(
397 "<p>Unable to run test <b>{0}</b>.<br>{1}<br>{2}</p>") 399 "<p>Unable to run test <b>{0}</b>.<br>{1}<br>{2}</p>")
398 .format(self.testName, exc_type, exc_value)) 400 .format(self.testName, exc_type, exc_value))
399 return 401 return
400 402
401 self.totalTests = nrTests 403 self.totalTests = nrTests
457 self.__setProgressColor("green") 459 self.__setProgressColor("green")
458 self.progressProgressBar.reset() 460 self.progressProgressBar.reset()
459 self.stopButton.setEnabled(True) 461 self.stopButton.setEnabled(True)
460 self.startButton.setEnabled(False) 462 self.startButton.setEnabled(False)
461 self.stopButton.setDefault(True) 463 self.stopButton.setDefault(True)
462 self.sbLabel.setText(self.trUtf8("Running")) 464 self.sbLabel.setText(self.tr("Running"))
463 self.progressLed.on() 465 self.progressLed.on()
464 QApplication.processEvents() 466 QApplication.processEvents()
465 467
466 self.startTime = time.time() 468 self.startTime = time.time()
467 469
481 self.startButton.setDefault(False) 483 self.startButton.setDefault(False)
482 else: 484 else:
483 self.startFailedButton.setDefault(False) 485 self.startFailedButton.setDefault(False)
484 self.startButton.setDefault(True) 486 self.startButton.setDefault(True)
485 if self.runCount == 1: 487 if self.runCount == 1:
486 self.sbLabel.setText(self.trUtf8("Ran {0} test in {1:.3f}s") 488 self.sbLabel.setText(self.tr("Ran {0} test in {1:.3f}s")
487 .format(self.runCount, self.timeTaken)) 489 .format(self.runCount, self.timeTaken))
488 else: 490 else:
489 self.sbLabel.setText(self.trUtf8("Ran {0} tests in {1:.3f}s") 491 self.sbLabel.setText(self.tr("Ran {0} tests in {1:.3f}s")
490 .format(self.runCount, self.timeTaken)) 492 .format(self.runCount, self.timeTaken))
491 self.progressLed.off() 493 self.progressLed.off()
492 494
493 self.unittestStopped.emit() 495 self.unittestStopped.emit()
494 496
500 @param exc string representation of the exception (string) 502 @param exc string representation of the exception (string)
501 @param id id of the test (string) 503 @param id id of the test (string)
502 """ 504 """
503 self.failCount += 1 505 self.failCount += 1
504 self.progressCounterFailureCount.setText(str(self.failCount)) 506 self.progressCounterFailureCount.setText(str(self.failCount))
505 itm = QListWidgetItem(self.trUtf8("Failure: {0}").format(test)) 507 itm = QListWidgetItem(self.tr("Failure: {0}").format(test))
506 itm.setData(Qt.UserRole, (test, exc)) 508 itm.setData(Qt.UserRole, (test, exc))
507 self.errorsListWidget.insertItem(0, itm) 509 self.errorsListWidget.insertItem(0, itm)
508 self.__failedTests.append(id) 510 self.__failedTests.append(id)
509 511
510 def testErrored(self, test, exc, id): 512 def testErrored(self, test, exc, id):
515 @param exc string representation of the exception (string) 517 @param exc string representation of the exception (string)
516 @param id id of the test (string) 518 @param id id of the test (string)
517 """ 519 """
518 self.errorCount += 1 520 self.errorCount += 1
519 self.progressCounterErrorCount.setText(str(self.errorCount)) 521 self.progressCounterErrorCount.setText(str(self.errorCount))
520 itm = QListWidgetItem(self.trUtf8("Error: {0}").format(test)) 522 itm = QListWidgetItem(self.tr("Error: {0}").format(test))
521 itm.setData(Qt.UserRole, (test, exc)) 523 itm.setData(Qt.UserRole, (test, exc))
522 self.errorsListWidget.insertItem(0, itm) 524 self.errorsListWidget.insertItem(0, itm)
523 self.__failedTests.append(id) 525 self.__failedTests.append(id)
524 526
525 def testSkipped(self, test, reason, id): 527 def testSkipped(self, test, reason, id):
530 @param reason reason for skipping the test (string) 532 @param reason reason for skipping the test (string)
531 @param id id of the test (string) 533 @param id id of the test (string)
532 """ 534 """
533 self.skippedCount += 1 535 self.skippedCount += 1
534 self.progressCounterSkippedCount.setText(str(self.skippedCount)) 536 self.progressCounterSkippedCount.setText(str(self.skippedCount))
535 itm = QListWidgetItem(self.trUtf8(" Skipped: {0}").format(reason)) 537 itm = QListWidgetItem(self.tr(" Skipped: {0}").format(reason))
536 itm.setForeground(Qt.blue) 538 itm.setForeground(Qt.blue)
537 self.testsListWidget.insertItem(1, itm) 539 self.testsListWidget.insertItem(1, itm)
538 540
539 def testFailedExpected(self, test, exc, id): 541 def testFailedExpected(self, test, exc, id):
540 """ 542 """
545 @param id id of the test (string) 547 @param id id of the test (string)
546 """ 548 """
547 self.expectedFailureCount += 1 549 self.expectedFailureCount += 1
548 self.progressCounterExpectedFailureCount.setText( 550 self.progressCounterExpectedFailureCount.setText(
549 str(self.expectedFailureCount)) 551 str(self.expectedFailureCount))
550 itm = QListWidgetItem(self.trUtf8(" Expected Failure")) 552 itm = QListWidgetItem(self.tr(" Expected Failure"))
551 itm.setForeground(Qt.blue) 553 itm.setForeground(Qt.blue)
552 self.testsListWidget.insertItem(1, itm) 554 self.testsListWidget.insertItem(1, itm)
553 555
554 def testSucceededUnexpected(self, test, id): 556 def testSucceededUnexpected(self, test, id):
555 """ 557 """
559 @param id id of the test (string) 561 @param id id of the test (string)
560 """ 562 """
561 self.unexpectedSuccessCount += 1 563 self.unexpectedSuccessCount += 1
562 self.progressCounterUnexpectedSuccessCount.setText( 564 self.progressCounterUnexpectedSuccessCount.setText(
563 str(self.unexpectedSuccessCount)) 565 str(self.unexpectedSuccessCount))
564 itm = QListWidgetItem(self.trUtf8(" Unexpected Success")) 566 itm = QListWidgetItem(self.tr(" Unexpected Success"))
565 itm.setForeground(Qt.red) 567 itm.setForeground(Qt.red)
566 self.testsListWidget.insertItem(1, itm) 568 self.testsListWidget.insertItem(1, itm)
567 569
568 def testStarted(self, test, doc): 570 def testStarted(self, test, doc):
569 """ 571 """
621 ui = Ui_UnittestStacktraceDialog() 623 ui = Ui_UnittestStacktraceDialog()
622 ui.setupUi(self.dlg) 624 ui.setupUi(self.dlg)
623 self.dlg.traceback = ui.traceback 625 self.dlg.traceback = ui.traceback
624 626
625 ui.showButton = ui.buttonBox.addButton( 627 ui.showButton = ui.buttonBox.addButton(
626 self.trUtf8("Show Source"), QDialogButtonBox.ActionRole) 628 self.tr("Show Source"), QDialogButtonBox.ActionRole)
627 ui.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 629 ui.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
628 630
629 self.dlg.setWindowTitle(text) 631 self.dlg.setWindowTitle(text)
630 ui.testLabel.setText(test) 632 ui.testLabel.setText(test)
631 ui.traceback.setPlainText(tracebackText) 633 ui.traceback.setPlainText(tracebackText)
632 634
633 # one more button if called from eric 635 # one more button if called from eric
634 if self.dbs: 636 if self.dbs:
635 ui.showButton.clicked[()].connect(self.__showSource) 637 ui.showButton.clicked.connect(self.__showSource)
636 else: 638 else:
637 ui.showButton.hide() 639 ui.showButton.hide()
638 640
639 # and now fire it up 641 # and now fire it up
640 self.dlg.show() 642 self.dlg.show()

eric ide

mercurial