PyUnit/UnittestDialog.py

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

eric ide

mercurial