PyUnit/UnittestDialog.py

changeset 6893
d29a7b8fab0f
parent 6892
c147620313c5
child 6894
df83ac87e0db
equal deleted inserted replaced
6892:c147620313c5 6893:d29a7b8fab0f
187 if prog in self.fileHistory: 187 if prog in self.fileHistory:
188 self.fileHistory.remove(prog) 188 self.fileHistory.remove(prog)
189 self.fileHistory.insert(0, prog) 189 self.fileHistory.insert(0, prog)
190 self.testsuitePicker.clear() 190 self.testsuitePicker.clear()
191 self.testsuitePicker.addItems(self.fileHistory) 191 self.testsuitePicker.addItems(self.fileHistory)
192 192
193 def insertTestName(self, testName): 193 def insertTestName(self, testName):
194 """ 194 """
195 Public slot to insert a test name into the testComboBox object. 195 Public slot to insert a test name into the testComboBox object.
196 196
197 @param testName name of the test to be inserted (string) 197 @param testName name of the test to be inserted (string)
202 if testName in self.testNameHistory: 202 if testName in self.testNameHistory:
203 self.testNameHistory.remove(testName) 203 self.testNameHistory.remove(testName)
204 self.testNameHistory.insert(0, testName) 204 self.testNameHistory.insert(0, testName)
205 self.testComboBox.clear() 205 self.testComboBox.clear()
206 self.testComboBox.addItems(self.testNameHistory) 206 self.testComboBox.addItems(self.testNameHistory)
207 207
208 @pyqtSlot() 208 @pyqtSlot()
209 def on_testsuitePicker_aboutToShowPathPickerDialog(self): 209 def on_testsuitePicker_aboutToShowPathPickerDialog(self):
210 """ 210 """
211 Private slot called before the test suite selection dialog is shown. 211 Private slot called before the test suite selection dialog is shown.
212 """ 212 """
222 .format(py2Extensions, py3Extensions) 222 .format(py2Extensions, py3Extensions)
223 else: 223 else:
224 fileFilter = self.tr("Python Files (*.py);;All Files (*)") 224 fileFilter = self.tr("Python Files (*.py);;All Files (*)")
225 self.testsuitePicker.setFilters(fileFilter) 225 self.testsuitePicker.setFilters(fileFilter)
226 226
227 defaultDirectory = Preferences.getMultiProject("Workspace")
228 if not defaultDirectory:
229 defaultDirectory = os.path.expanduser("~")
230 if self.__dbs:
231 project = e5App().getObject("Project")
232 if self.__forProject and project.isOpen():
233 defaultDirectory = project.getProjectPath()
234
227 @pyqtSlot(str) 235 @pyqtSlot(str)
228 def on_testsuitePicker_pathSelected(self, suite): 236 def on_testsuitePicker_pathSelected(self, suite):
229 """ 237 """
230 Private slot called after a test suite has been selected. 238 Private slot called after a test suite has been selected.
231 239
232 @param suite file name of the test suite 240 @param suite file name of the test suite
233 @type str 241 @type str
234 """ 242 """
235 self.insertProg(suite) 243 self.insertProg(suite)
236 244
237 def on_buttonBox_clicked(self, button): 245 def on_buttonBox_clicked(self, button):
238 """ 246 """
239 Private slot called by a button of the button box clicked. 247 Private slot called by a button of the button box clicked.
240 248
241 @param button button that was clicked (QAbstractButton) 249 @param button button that was clicked (QAbstractButton)
244 self.on_startButton_clicked() 252 self.on_startButton_clicked()
245 elif button == self.stopButton: 253 elif button == self.stopButton:
246 self.on_stopButton_clicked() 254 self.on_stopButton_clicked()
247 elif button == self.startFailedButton: 255 elif button == self.startFailedButton:
248 self.on_startButton_clicked(failedOnly=True) 256 self.on_startButton_clicked(failedOnly=True)
249 257
250 @pyqtSlot() 258 @pyqtSlot()
251 def on_startButton_clicked(self, failedOnly=False): 259 def on_startButton_clicked(self, failedOnly=False):
252 """ 260 """
253 Private slot to start the test. 261 Private slot to start the test.
254 262
383 if cover: 391 if cover:
384 cover.stop() 392 cover.stop()
385 cover.save() 393 cover.save()
386 self.__setStoppedMode() 394 self.__setStoppedMode()
387 sys.path = self.savedSysPath 395 sys.path = self.savedSysPath
388 396
389 def __UTPrepared(self, nrTests, exc_type, exc_value): 397 def __UTPrepared(self, nrTests, exc_type, exc_value):
390 """ 398 """
391 Private slot to handle the utPrepared signal. 399 Private slot to handle the utPrepared signal.
392 400
393 If the unittest suite was loaded successfully, we ask the 401 If the unittest suite was loaded successfully, we ask the
407 return 415 return
408 416
409 self.totalTests = nrTests 417 self.totalTests = nrTests
410 self.__setRunningMode() 418 self.__setRunningMode()
411 self.__dbs.remoteUTRun() 419 self.__dbs.remoteUTRun()
412 420
413 @pyqtSlot() 421 @pyqtSlot()
414 def on_stopButton_clicked(self): 422 def on_stopButton_clicked(self):
415 """ 423 """
416 Private slot to stop the test. 424 Private slot to stop the test.
417 """ 425 """
418 if self.__dbs: 426 if self.__dbs:
419 self.__dbs.remoteUTStop() 427 self.__dbs.remoteUTStop()
420 elif self.testResult: 428 elif self.testResult:
421 self.testResult.stop() 429 self.testResult.stop()
422 430
423 def on_errorsListWidget_currentTextChanged(self, text): 431 def on_errorsListWidget_currentTextChanged(self, text):
424 """ 432 """
425 Private slot to handle the highlighted signal. 433 Private slot to handle the highlighted signal.
426 434
427 @param text current text (string) 435 @param text current text (string)
434 text, Qt.MatchFlags(Qt.MatchExactly)) 442 text, Qt.MatchFlags(Qt.MatchExactly))
435 if len(foundItems) > 0: 443 if len(foundItems) > 0:
436 itm = foundItems[0] 444 itm = foundItems[0]
437 self.testsListWidget.setCurrentItem(itm) 445 self.testsListWidget.setCurrentItem(itm)
438 self.testsListWidget.scrollToItem(itm) 446 self.testsListWidget.scrollToItem(itm)
439 447
440 def __setRunningMode(self): 448 def __setRunningMode(self):
441 """ 449 """
442 Private method to set the GUI in running mode. 450 Private method to set the GUI in running mode.
443 """ 451 """
444 self.running = True 452 self.running = True
449 self.errorCount = 0 457 self.errorCount = 0
450 self.skippedCount = 0 458 self.skippedCount = 0
451 self.expectedFailureCount = 0 459 self.expectedFailureCount = 0
452 self.unexpectedSuccessCount = 0 460 self.unexpectedSuccessCount = 0
453 self.remainingCount = self.totalTests 461 self.remainingCount = self.totalTests
454 462
455 # reset the GUI 463 # reset the GUI
456 self.progressCounterRunCount.setText(str(self.runCount)) 464 self.progressCounterRunCount.setText(str(self.runCount))
457 self.progressCounterRemCount.setText(str(self.remainingCount)) 465 self.progressCounterRemCount.setText(str(self.remainingCount))
458 self.progressCounterFailureCount.setText(str(self.failCount)) 466 self.progressCounterFailureCount.setText(str(self.failCount))
459 self.progressCounterErrorCount.setText(str(self.errorCount)) 467 self.progressCounterErrorCount.setText(str(self.errorCount))
473 self.sbLabel.setText(self.tr("Running")) 481 self.sbLabel.setText(self.tr("Running"))
474 self.progressLed.on() 482 self.progressLed.on()
475 QApplication.processEvents() 483 QApplication.processEvents()
476 484
477 self.startTime = time.time() 485 self.startTime = time.time()
478 486
479 def __setStoppedMode(self): 487 def __setStoppedMode(self):
480 """ 488 """
481 Private method to set the GUI in stopped mode. 489 Private method to set the GUI in stopped mode.
482 """ 490 """
483 self.stopTime = time.time() 491 self.stopTime = time.time()
502 self.tr("Ran {0} tests in {1:.3f}s") 510 self.tr("Ran {0} tests in {1:.3f}s")
503 .format(self.runCount, self.timeTaken)) 511 .format(self.runCount, self.timeTaken))
504 self.progressLed.off() 512 self.progressLed.off()
505 513
506 self.unittestStopped.emit() 514 self.unittestStopped.emit()
507 515
508 def testFailed(self, test, exc, testId): 516 def testFailed(self, test, exc, testId):
509 """ 517 """
510 Public method called if a test fails. 518 Public method called if a test fails.
511 519
512 @param test name of the test (string) 520 @param test name of the test (string)
517 self.progressCounterFailureCount.setText(str(self.failCount)) 525 self.progressCounterFailureCount.setText(str(self.failCount))
518 itm = QListWidgetItem(self.tr("Failure: {0}").format(test)) 526 itm = QListWidgetItem(self.tr("Failure: {0}").format(test))
519 itm.setData(Qt.UserRole, (test, exc)) 527 itm.setData(Qt.UserRole, (test, exc))
520 self.errorsListWidget.insertItem(0, itm) 528 self.errorsListWidget.insertItem(0, itm)
521 self.__failedTests.append(testId) 529 self.__failedTests.append(testId)
522 530
523 def testErrored(self, test, exc, testId): 531 def testErrored(self, test, exc, testId):
524 """ 532 """
525 Public method called if a test errors. 533 Public method called if a test errors.
526 534
527 @param test name of the test (string) 535 @param test name of the test (string)
532 self.progressCounterErrorCount.setText(str(self.errorCount)) 540 self.progressCounterErrorCount.setText(str(self.errorCount))
533 itm = QListWidgetItem(self.tr("Error: {0}").format(test)) 541 itm = QListWidgetItem(self.tr("Error: {0}").format(test))
534 itm.setData(Qt.UserRole, (test, exc)) 542 itm.setData(Qt.UserRole, (test, exc))
535 self.errorsListWidget.insertItem(0, itm) 543 self.errorsListWidget.insertItem(0, itm)
536 self.__failedTests.append(testId) 544 self.__failedTests.append(testId)
537 545
538 def testSkipped(self, test, reason, testId): 546 def testSkipped(self, test, reason, testId):
539 """ 547 """
540 Public method called if a test was skipped. 548 Public method called if a test was skipped.
541 549
542 @param test name of the test (string) 550 @param test name of the test (string)
546 self.skippedCount += 1 554 self.skippedCount += 1
547 self.progressCounterSkippedCount.setText(str(self.skippedCount)) 555 self.progressCounterSkippedCount.setText(str(self.skippedCount))
548 itm = QListWidgetItem(self.tr(" Skipped: {0}").format(reason)) 556 itm = QListWidgetItem(self.tr(" Skipped: {0}").format(reason))
549 itm.setForeground(Qt.blue) 557 itm.setForeground(Qt.blue)
550 self.testsListWidget.insertItem(1, itm) 558 self.testsListWidget.insertItem(1, itm)
551 559
552 def testFailedExpected(self, test, exc, testId): 560 def testFailedExpected(self, test, exc, testId):
553 """ 561 """
554 Public method called if a test fails expectedly. 562 Public method called if a test fails expectedly.
555 563
556 @param test name of the test (string) 564 @param test name of the test (string)
561 self.progressCounterExpectedFailureCount.setText( 569 self.progressCounterExpectedFailureCount.setText(
562 str(self.expectedFailureCount)) 570 str(self.expectedFailureCount))
563 itm = QListWidgetItem(self.tr(" Expected Failure")) 571 itm = QListWidgetItem(self.tr(" Expected Failure"))
564 itm.setForeground(Qt.blue) 572 itm.setForeground(Qt.blue)
565 self.testsListWidget.insertItem(1, itm) 573 self.testsListWidget.insertItem(1, itm)
566 574
567 def testSucceededUnexpected(self, test, testId): 575 def testSucceededUnexpected(self, test, testId):
568 """ 576 """
569 Public method called if a test succeeds unexpectedly. 577 Public method called if a test succeeds unexpectedly.
570 578
571 @param test name of the test (string) 579 @param test name of the test (string)
575 self.progressCounterUnexpectedSuccessCount.setText( 583 self.progressCounterUnexpectedSuccessCount.setText(
576 str(self.unexpectedSuccessCount)) 584 str(self.unexpectedSuccessCount))
577 itm = QListWidgetItem(self.tr(" Unexpected Success")) 585 itm = QListWidgetItem(self.tr(" Unexpected Success"))
578 itm.setForeground(Qt.red) 586 itm.setForeground(Qt.red)
579 self.testsListWidget.insertItem(1, itm) 587 self.testsListWidget.insertItem(1, itm)
580 588
581 def testStarted(self, test, doc): 589 def testStarted(self, test, doc):
582 """ 590 """
583 Public method called if a test is about to be run. 591 Public method called if a test is about to be run.
584 592
585 @param test name of the started test (string) 593 @param test name of the started test (string)
588 if doc: 596 if doc:
589 self.testsListWidget.insertItem(0, " {0}".format(doc)) 597 self.testsListWidget.insertItem(0, " {0}".format(doc))
590 self.testsListWidget.insertItem(0, test) 598 self.testsListWidget.insertItem(0, test)
591 if self.__dbs is None: 599 if self.__dbs is None:
592 QApplication.processEvents() 600 QApplication.processEvents()
593 601
594 def testFinished(self): 602 def testFinished(self):
595 """ 603 """
596 Public method called if a test has finished. 604 Public method called if a test has finished.
597 605
598 <b>Note</b>: It is also called if it has already failed or errored. 606 <b>Note</b>: It is also called if it has already failed or errored.
607 if self.errorCount: 615 if self.errorCount:
608 self.__setProgressColor("red") 616 self.__setProgressColor("red")
609 elif self.failCount: 617 elif self.failCount:
610 self.__setProgressColor("orange") 618 self.__setProgressColor("orange")
611 self.progressProgressBar.setValue(self.runCount) 619 self.progressProgressBar.setValue(self.runCount)
612 620
613 def on_errorsListWidget_itemDoubleClicked(self, lbitem): 621 def on_errorsListWidget_itemDoubleClicked(self, lbitem):
614 """ 622 """
615 Private slot called by doubleclicking an errorlist entry. 623 Private slot called by doubleclicking an errorlist entry.
616 624
617 It will popup a dialog showing the stacktrace. 625 It will popup a dialog showing the stacktrace.
622 @param lbitem the listbox item that was double clicked 630 @param lbitem the listbox item that was double clicked
623 """ 631 """
624 self.errListIndex = self.errorsListWidget.row(lbitem) 632 self.errListIndex = self.errorsListWidget.row(lbitem)
625 text = lbitem.text() 633 text = lbitem.text()
626 self.on_errorsListWidget_currentTextChanged(text) 634 self.on_errorsListWidget_currentTextChanged(text)
627 635
628 # get the error info 636 # get the error info
629 test, tracebackText = lbitem.data(Qt.UserRole) 637 test, tracebackText = lbitem.data(Qt.UserRole)
630 638
631 # now build the dialog 639 # now build the dialog
632 from .Ui_UnittestStacktraceDialog import Ui_UnittestStacktraceDialog 640 from .Ui_UnittestStacktraceDialog import Ui_UnittestStacktraceDialog
633 self.dlg = QDialog(self) 641 self.dlg = QDialog(self)
634 ui = Ui_UnittestStacktraceDialog() 642 ui = Ui_UnittestStacktraceDialog()
635 ui.setupUi(self.dlg) 643 ui.setupUi(self.dlg)
646 ui.traceback.setPlainText(tracebackText) 654 ui.traceback.setPlainText(tracebackText)
647 655
648 # and now fire it up 656 # and now fire it up
649 self.dlg.show() 657 self.dlg.show()
650 self.dlg.exec_() 658 self.dlg.exec_()
651 659
652 def __showSource(self): 660 def __showSource(self):
653 """ 661 """
654 Private slot to show the source of a traceback in an eric6 editor. 662 Private slot to show the source of a traceback in an eric6 editor.
655 """ 663 """
656 # get the error info 664 # get the error info
725 733
726 @param parent The parent widget. 734 @param parent The parent widget.
727 """ 735 """
728 super(QtTestResult, self).__init__() 736 super(QtTestResult, self).__init__()
729 self.parent = parent 737 self.parent = parent
730 738
731 def addFailure(self, test, err): 739 def addFailure(self, test, err):
732 """ 740 """
733 Public method called if a test failed. 741 Public method called if a test failed.
734 742
735 @param test reference to the test object 743 @param test reference to the test object
736 @param err error traceback 744 @param err error traceback
737 """ 745 """
738 super(QtTestResult, self).addFailure(test, err) 746 super(QtTestResult, self).addFailure(test, err)
739 tracebackLines = self._exc_info_to_string(err, test) 747 tracebackLines = self._exc_info_to_string(err, test)
740 self.parent.testFailed(str(test), tracebackLines, test.id()) 748 self.parent.testFailed(str(test), tracebackLines, test.id())
741 749
742 def addError(self, test, err): 750 def addError(self, test, err):
743 """ 751 """
744 Public method called if a test errored. 752 Public method called if a test errored.
745 753
746 @param test reference to the test object 754 @param test reference to the test object
747 @param err error traceback 755 @param err error traceback
748 """ 756 """
749 super(QtTestResult, self).addError(test, err) 757 super(QtTestResult, self).addError(test, err)
750 tracebackLines = self._exc_info_to_string(err, test) 758 tracebackLines = self._exc_info_to_string(err, test)
751 self.parent.testErrored(str(test), tracebackLines, test.id()) 759 self.parent.testErrored(str(test), tracebackLines, test.id())
752 760
753 def addSkip(self, test, reason): 761 def addSkip(self, test, reason):
754 """ 762 """
755 Public method called if a test was skipped. 763 Public method called if a test was skipped.
756 764
757 @param test reference to the test object 765 @param test reference to the test object
758 @param reason reason for skipping the test (string) 766 @param reason reason for skipping the test (string)
759 """ 767 """
760 super(QtTestResult, self).addSkip(test, reason) 768 super(QtTestResult, self).addSkip(test, reason)
761 self.parent.testSkipped(str(test), reason, test.id()) 769 self.parent.testSkipped(str(test), reason, test.id())
762 770
763 def addExpectedFailure(self, test, err): 771 def addExpectedFailure(self, test, err):
764 """ 772 """
765 Public method called if a test failed expected. 773 Public method called if a test failed expected.
766 774
767 @param test reference to the test object 775 @param test reference to the test object
768 @param err error traceback 776 @param err error traceback
769 """ 777 """
770 super(QtTestResult, self).addExpectedFailure(test, err) 778 super(QtTestResult, self).addExpectedFailure(test, err)
771 tracebackLines = self._exc_info_to_string(err, test) 779 tracebackLines = self._exc_info_to_string(err, test)
772 self.parent.testFailedExpected(str(test), tracebackLines, test.id()) 780 self.parent.testFailedExpected(str(test), tracebackLines, test.id())
773 781
774 def addUnexpectedSuccess(self, test): 782 def addUnexpectedSuccess(self, test):
775 """ 783 """
776 Public method called if a test succeeded expectedly. 784 Public method called if a test succeeded expectedly.
777 785
778 @param test reference to the test object 786 @param test reference to the test object
779 """ 787 """
780 super(QtTestResult, self).addUnexpectedSuccess(test) 788 super(QtTestResult, self).addUnexpectedSuccess(test)
781 self.parent.testSucceededUnexpected(str(test), test.id()) 789 self.parent.testSucceededUnexpected(str(test), test.id())
782 790
783 def startTest(self, test): 791 def startTest(self, test):
784 """ 792 """
785 Public method called at the start of a test. 793 Public method called at the start of a test.
786 794
787 @param test Reference to the test object 795 @param test Reference to the test object

eric ide

mercurial