# eric7.PyUnit.UnittestDialog

Module implementing the UI to the pyunit package.

### Global Attributes

None

### Classes

QtTestResult | A TestResult derivative to work with a graphical GUI.
UnittestDialog | Class implementing the UI to the pyunit package.
UnittestWindow | Main window class for the standalone dialog.

### Functions

clearSavedHistories | Function to clear the saved history lists.

## QtTestResult

A TestResult derivative to work with a graphical GUI.

For more details see pyunit.py of the standard Python distribution.

### Derived from

unittest.TestResult

### Class Attributes

None

### Class Methods

None

### Methods

QtTestResult | Constructor
addError | Public method called if a test errored.
addExpectedFailure | Public method called if a test failed expected.
addFailure | Public method called if a test failed.
addSkip | Public method called if a test was skipped.
addSubTest | Public method called for each subtest to record its result.
addUnexpectedSuccess | Public method called if a test succeeded expectedly.
startTest | Public method called at the start of a test.
stopTest | Public method called at the end of a test.

### Static Methods

None

#### QtTestResult (Constructor)

QtTestResult(parent, failfast)

Constructor

parent (UnittestDialog)
  reference to the parent widget
failfast (bool)
  flag indicating to stop at the first error

#### QtTestResult.addError

addError(test, err)

Public method called if a test errored.

test
  reference to the test object
err
  error traceback

#### QtTestResult.addExpectedFailure

addExpectedFailure(test, err)

Public method called if a test failed expected.

test
  reference to the test object
err
  error traceback

#### QtTestResult.addFailure

addFailure(test, err)

Public method called if a test failed.

test
  reference to the test object
err
  error traceback

#### QtTestResult.addSkip

addSkip(test, reason)

Public method called if a test was skipped.

test
  reference to the test object
reason
  reason for skipping the test (string)

#### QtTestResult.addSubTest

addSubTest(test, subtest, err)

Public method called for each subtest to record its result.

test
  reference to the test object
subtest
  reference to the subtest object
err
  error traceback

#### QtTestResult.addUnexpectedSuccess

addUnexpectedSuccess(test)

Public method called if a test succeeded expectedly.

test
  reference to the test object

#### QtTestResult.startTest

startTest(test)

Public method called at the start of a test.

test
  Reference to the test object

#### QtTestResult.stopTest

stopTest(test)

Public method called at the end of a test.

test
  Reference to the test object

Up

## UnittestDialog

Class implementing the UI to the pyunit package.

### Signals

unittestFile(str, int, bool)
  emitted to show the source of a unittest file
unittestStopped()
  emitted after a unit test was run

### Derived from

QWidget, Ui_UnittestDialog

### Class Attributes

ErrorsInfoRole
FailedExpectedColorDarkTheme
FailedExpectedColorLightTheme
SkippedColorDarkTheme
SkippedColorLightTheme
SucceededUnexpectedColorDarkTheme
SucceededUnexpectedColorLightTheme
TestCaseFileRole
TestCaseNameRole

### Class Methods

None

### Methods

UnittestDialog | Constructor
__UTDiscovered | Private slot to handle the utDiscovered signal.
__UTPrepared | Private slot to handle the utPrepared signal.
__assembleTestCasesList | Private method to assemble a list of test cases included in a test suite.
__discover | Private slot to discover unit test but don't run them.
__findDiscoveryItem | Private method to find an item given the module path.
__loadRecent | Private method to load the most recently used lists.
__openEditor | Private method to open an editor window for the given file.
__populateDiscoveryResults | Private method to populate the test discovery results list.
__populateVenvComboBox | Private method to (re-)populate the virtual environments selector.
__saveRecent | Private method to save the most recently used lists.
__selectedTestCases | Private method to assemble the list of selected test cases and suites.
__setProgressColor | Private method to set the color of the progress color label.
__setRunningMode | Private method to set the GUI in running mode.
__setStoppedMode | Private method to set the GUI in stopped mode.
__showSource | Private slot to show the source of a traceback in an eric editor.
__stopTests | Private slot to stop the test.
clearRecent | Public slot to clear the recently used lists.
closeEvent | Protected method to handle the close event.
hasFailedTests | Public method to check, if there are failed tests from the last run.
insertDiscovery | Public slot to insert the discovery start directory into the discoveryPicker object.
insertProg | Public slot to insert the filename prog into the testsuitePicker object.
insertTestName | Public slot to insert a test name into the testComboBox object.
keyPressEvent | Protected slot to handle key press events.
on_buttonBox_clicked | Private slot called by a button of the button box clicked.
on_discoverCheckBox_toggled | Private slot handling state changes of the 'discover' checkbox.
on_discoveryList_itemChanged | Private slot handling the user checking or unchecking an item.
on_discoveryList_itemDoubleClicked | Private slot handling the user double clicking an item.
on_errorsListWidget_currentTextChanged | Private slot to handle the highlighted signal.
on_errorsListWidget_itemDoubleClicked | Private slot called by doubleclicking an errorlist entry.
on_testsuitePicker_aboutToShowPathPickerDialog | Private slot called before the test suite selection dialog is shown.
on_testsuitePicker_editTextChanged | Private slot handling changes of the test suite path.
on_testsuitePicker_pathSelected | Private slot called after a test suite has been selected.
setProjectMode | Public method to set the project mode of the dialog.
startTests | Public slot to start the test.
testErrored | Public method called if a test errors.
testFailed | Public method called if a test fails.
testFailedExpected | Public method called if a test fails as expected.
testFinished | Public method called if a test has finished.
testSkipped | Public method called if a test was skipped.
testStarted | Public method called if a test is about to be run.
testSucceededUnexpected | Public method called if a test succeeds unexpectedly.

### Static Methods

None

#### UnittestDialog (Constructor)

UnittestDialog(prog=None, dbs=None, ui=None, parent=None, name=None)

Constructor

prog (str)
  filename of the program to open
dbs (DebugServer)
  reference to the debug server object. It is an indication whether we were called from within the eric IDE.
ui (UserInterface)
  reference to the UI object
parent (QWidget)
  parent widget of this dialog
name (str)
  name of this dialog

#### UnittestDialog.__UTDiscovered

__UTDiscovered(testCases, exc_type, exc_value)

Private slot to handle the utDiscovered signal.

If the unittest suite was loaded successfully, we ask the client to run the test suite.

testCases (str)
  list of detected test cases
exc_type (str)
  exception type occured during discovery
exc_value (str)
  value of exception occured during discovery

#### UnittestDialog.__UTPrepared

__UTPrepared(nrTests, exc_type, exc_value)

Private slot to handle the utPrepared signal.

If the unittest suite was loaded successfully, we ask the client to run the test suite.

nrTests
  number of tests contained in the test suite (integer)
exc_type
  type of exception occured during preparation (string)
exc_value
  value of exception occured during preparation (string)

#### UnittestDialog.__assembleTestCasesList

__assembleTestCasesList(suite, start)

Private method to assemble a list of test cases included in a test suite.

suite (unittest.TestSuite)
  test suite to be inspected
start (str)
  name of directory discovery was started at

Return:
  list of tuples containing the test case ID, a short description and the path of the test file name

Return Type:
  list of tuples of (str, str, str)

#### UnittestDialog.__discover

__discover()

Private slot to discover unit test but don't run them.

#### UnittestDialog.__findDiscoveryItem

__findDiscoveryItem(modulePath)

Private method to find an item given the module path.

modulePath (str)
  path of the module in dotted notation

Return:
  reference to the item or None

Return Type:
  QTreeWidgetItem or None

#### UnittestDialog.__loadRecent

__loadRecent()

Private method to load the most recently used lists.

#### UnittestDialog.__openEditor

__openEditor(filename, linenumber)

Private method to open an editor window for the given file.

Note: This method opens an editor window when the unittest dialog is called as a standalone application.

filename (str)
  path of the file to be opened
linenumber (int)
  line number to place the cursor at

#### UnittestDialog.__populateDiscoveryResults

__populateDiscoveryResults(tests)

Private method to populate the test discovery results list.

tests (list of tuples of (str, str, str))
  list of tuples containing the discovery results

#### UnittestDialog.__populateVenvComboBox

__populateVenvComboBox()

Private method to (re-)populate the virtual environments selector.

#### UnittestDialog.__saveRecent

__saveRecent()

Private method to save the most recently used lists.

#### UnittestDialog.__selectedTestCases

__selectedTestCases(parent=None)

Private method to assemble the list of selected test cases and suites.

parent (QTreeWidgetItem)
  reference to the parent item

Return:
  list of selected test cases

Return Type:
  list of str

#### UnittestDialog.__setProgressColor

__setProgressColor(color)

Private method to set the color of the progress color label.

color
  colour to be shown (string)

#### UnittestDialog.__setRunningMode

__setRunningMode()

Private method to set the GUI in running mode.

#### UnittestDialog.__setStoppedMode

__setStoppedMode()

Private method to set the GUI in stopped mode.

#### UnittestDialog.__showSource

__showSource()

Private slot to show the source of a traceback in an eric editor.

#### UnittestDialog.__stopTests

__stopTests()

Private slot to stop the test.

#### UnittestDialog.clearRecent

clearRecent()

Public slot to clear the recently used lists.

#### UnittestDialog.closeEvent

closeEvent(event)

Protected method to handle the close event.

event (QCloseEvent)
  close event

#### UnittestDialog.hasFailedTests

hasFailedTests()

Public method to check, if there are failed tests from the last run.

Return:
  flag indicating the presence of failed tests (boolean)

#### UnittestDialog.insertDiscovery

insertDiscovery(start)

Public slot to insert the discovery start directory into the discoveryPicker object.

start (str)
  start directory name to be inserted

#### UnittestDialog.insertProg

insertProg(prog)

Public slot to insert the filename prog into the testsuitePicker object.

prog
  filename to be inserted (string)

#### UnittestDialog.insertTestName

insertTestName(testName)

Public slot to insert a test name into the testComboBox object.

testName
  name of the test to be inserted (string)

#### UnittestDialog.keyPressEvent

keyPressEvent(evt)

Protected slot to handle key press events.

evt
  key press event to handle (QKeyEvent)

#### UnittestDialog.on_buttonBox_clicked

on_buttonBox_clicked(button)

Private slot called by a button of the button box clicked.

button
  button that was clicked (QAbstractButton)

#### UnittestDialog.on_discoverCheckBox_toggled

on_discoverCheckBox_toggled(checked)

Private slot handling state changes of the 'discover' checkbox.

checked (bool)
  state of the checkbox

#### UnittestDialog.on_discoveryList_itemChanged

on_discoveryList_itemChanged(item, column)

Private slot handling the user checking or unchecking an item.

item (QTreeWidgetItem)
  reference to the item
column (int)
  changed column

#### UnittestDialog.on_discoveryList_itemDoubleClicked

on_discoveryList_itemDoubleClicked(item, column)

Private slot handling the user double clicking an item.

item (QTreeWidgetItem)
  reference to the item
column (int)
  column of the double click

#### UnittestDialog.on_errorsListWidget_currentTextChanged

on_errorsListWidget_currentTextChanged(text)

Private slot to handle the highlighted signal.

text
  current text (string)

#### UnittestDialog.on_errorsListWidget_itemDoubleClicked

on_errorsListWidget_itemDoubleClicked(lbitem)

Private slot called by doubleclicking an errorlist entry.

It will popup a dialog showing the stacktrace. If called from eric, an additional button is displayed to show the python source in an eric source viewer (in erics main window.

lbitem
  the listbox item that was double clicked

#### UnittestDialog.on_testsuitePicker_aboutToShowPathPickerDialog

on_testsuitePicker_aboutToShowPathPickerDialog()

Private slot called before the test suite selection dialog is shown.

#### UnittestDialog.on_testsuitePicker_editTextChanged

on_testsuitePicker_editTextChanged(path)

Private slot handling changes of the test suite path.

path (str)
  path of the test suite file

#### UnittestDialog.on_testsuitePicker_pathSelected

on_testsuitePicker_pathSelected(suite)

Private slot called after a test suite has been selected.

suite (str)
  file name of the test suite

#### UnittestDialog.setProjectMode

setProjectMode(forProject)

Public method to set the project mode of the dialog.

forProject (bool)
  flag indicating to run for the open project

#### UnittestDialog.startTests

startTests(failedOnly=False)

Public slot to start the test.

failedOnly
  flag indicating to run only failed tests (boolean)

#### UnittestDialog.testErrored

testErrored(test, exc, testId)

Public method called if a test errors.

test
  name of the test (string)
exc
  string representation of the exception (string)
testId
  id of the test (string)

#### UnittestDialog.testFailed

testFailed(test, exc, testId)

Public method called if a test fails.

test
  name of the test (string)
exc
  string representation of the exception (string)
testId
  id of the test (string)

#### UnittestDialog.testFailedExpected

testFailedExpected(test, exc, testId)

Public method called if a test fails as expected.

test
  name of the test (string)
exc
  string representation of the exception (string)
testId
  id of the test (string)

#### UnittestDialog.testFinished

testFinished()

Public method called if a test has finished.

Note: It is also called if it has already failed or errored.

#### UnittestDialog.testSkipped

testSkipped(test, reason, testId)

Public method called if a test was skipped.

test
  name of the test (string)
reason
  reason for skipping the test (string)
testId
  id of the test (string)

#### UnittestDialog.testStarted

testStarted(test, doc)

Public method called if a test is about to be run.

test
  name of the started test (string)
doc
  documentation of the started test (string)

#### UnittestDialog.testSucceededUnexpected

testSucceededUnexpected(test, testId)

Public method called if a test succeeds unexpectedly.

test
  name of the test (string)
testId
  id of the test (string)

Up

## UnittestWindow

Main window class for the standalone dialog.

### Derived from

EricMainWindow

### Class Attributes

None

### Class Methods

None

### Methods

UnittestWindow | Constructor
eventFilter | Public method to filter events.

### Static Methods

None

#### UnittestWindow (Constructor)

UnittestWindow(prog=None, parent=None)

Constructor

prog
  filename of the program to open
parent
  reference to the parent widget (QWidget)

#### UnittestWindow.eventFilter

eventFilter(obj, event)

Public method to filter events.

obj
  reference to the object the event is meant for (QObject)
event
  reference to the event object (QEvent)

Return:
  flag indicating, whether the event was handled (boolean)

Up

## clearSavedHistories

clearSavedHistories(self)

Function to clear the saved history lists.

Up