# eric7.Testing.TestingWidget

Module implementing a widget to orchestrate unit test execution.

### Global Attributes

None

### Classes

TestingWidget | Class implementing a widget to orchestrate unit test execution.
TestingWidgetModes | Class defining the various modes of the testing widget.
TestingWindow | Main window class for the standalone dialog.

### Functions

clearSavedHistories | Function to clear the saved history lists.

## TestingWidget

Class implementing a widget to orchestrate unit test execution.

### Signals

testFile(str, int, bool)
  emitted to show the source of a test file
testRunStopped()
  emitted after a test run has finished

### Derived from

QWidget, Ui_TestingWidget

### Class Attributes

None

### Class Methods

None

### Methods

TestingWidget | Constructor
__adjustPendingState | Private method to change the status indicator of all still pending tests to "not run".
__coverageData | Private slot to handle the 'coverageData' signal of the executor.
__insertDiscovery | Private slot to insert the discovery start directory into the discoveryPicker object.
__insertHistory | Private slot to insert an item into a history object.
__insertTestFile | Private slot to insert a test file name into the testsuitePicker object.
__insertTestName | Private slot to insert a test name into the testComboBox object.
__loadRecent | Private method to load the most recently used lists.
__openEditor | Private method to open an editor window for the given file.
__populateTestFrameworkComboBox | Private method to (re-)populate the test framework selector.
__populateVenvComboBox | Private method to (re-)populate the virtual environments selector.
__processTestResult | Private slot to handle the receipt of a test result object.
__projectClosed | Private slot to handle a project being closed.
__projectOpened | Private slot to handle a project being opened.
__resetResults | Private slot to reset the test results tab and data.
__saveRecent | Private method to save the most recently used lists.
__setIdleMode | Private slot to switch the widget to idle mode.
__setRunningMode | Private slot to switch the widget to running mode.
__setStatusLabel | Private slot to set the status label to the text sent by the model.
__setStoppedMode | Private slot to switch the widget to stopped mode.
__showCoverageDialog | Private slot to show a code coverage dialog for the most recent test run.
__showLogOutput | Private slot to show the output of the most recent test run.
__showSource | Private slot to show the source of a traceback in an editor.
__stopTests | Private slot to stop the current test run.
__testProcessFinished | Private slot to handle the 'testFinished' signal of the executor.
__testRunAboutToBeStarted | Private slot to handle the 'testRunAboutToBeStarted' signal of the executor.
__testRunFinished | Private slot to handle the 'testRunFinished' signal of the executor.
__testStarted | Private slot handling the 'startTest' signal of the executor.
__testsCollectError | Private slot handling the 'collectError' signal of the executor.
__testsCollected | Private slot handling the 'collected' signal of the executor.
__testsStopped | Private slot to handle the 'stop' signal of the executor.
__updateButtonBoxButtons | Private slot to update the state of the buttons of the button box.
__updateCoverage | Private slot to update the state of the coverage checkbox depending on the selected framework's capabilities.
__updateProgress | Private slot update the progress indicators.
clearRecent | Public slot to clear the recently used lists.
closeEvent | Protected method to handle the close event.
getFailedTests | Public method to get the list of failed tests (if any).
getResultsModel | Public method to get a reference to the model containing the test result data.
hasFailedTests | Public method to check for failed tests.
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_frameworkComboBox_currentIndexChanged | Private slot handling the selection of a test framework.
on_testsuitePicker_aboutToShowPathPickerDialog | Private slot called before the test file selection dialog is shown.
on_venvComboBox_currentIndexChanged | Private slot handling the selection of a virtual environment.
on_versionsButton_clicked | Private slot to show the versions of available plugins.
setTestFile | Public slot to set the given test file as the current one.
startTests | Public slot to start the test run.

### Static Methods

None

#### TestingWidget (Constructor)

TestingWidget(testfile=None, parent=None)

Constructor

testfile (str)
  file name of the test to load
parent (QWidget (optional))
  reference to the parent widget (defaults to None)

#### TestingWidget.__adjustPendingState

__adjustPendingState()

Private method to change the status indicator of all still pending tests to "not run".

#### TestingWidget.__coverageData

__coverageData(coverageFile)

Private slot to handle the 'coverageData' signal of the executor.

coverageFile (str)
  file containing the coverage data

#### TestingWidget.__insertDiscovery

__insertDiscovery(start)

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

start (str)
  start directory name to be inserted

#### TestingWidget.__insertHistory

__insertHistory(widget, history, item)

Private slot to insert an item into a history object.

widget (QComboBox or EricComboPathPicker)
  reference to the widget
history (list of str)
  array containing the history
item (str)
  item to be inserted

#### TestingWidget.__insertTestFile

__insertTestFile(prog)

Private slot to insert a test file name into the testsuitePicker object.

prog (str)
  test file name to be inserted

#### TestingWidget.__insertTestName

__insertTestName(testName)

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

testName (str)
  name of the test to be inserted

#### TestingWidget.__loadRecent

__loadRecent()

Private method to load the most recently used lists.

#### TestingWidget.__openEditor

__openEditor(filename, linenumber=1)

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

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

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

#### TestingWidget.__populateTestFrameworkComboBox

__populateTestFrameworkComboBox()

Private method to (re-)populate the test framework selector.

#### TestingWidget.__populateVenvComboBox

__populateVenvComboBox()

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

#### TestingWidget.__processTestResult

__processTestResult(result)

Private slot to handle the receipt of a test result object.

result (TestResult)
  test result object

#### TestingWidget.__projectClosed

__projectClosed()

Private slot to handle a project being closed.

#### TestingWidget.__projectOpened

__projectOpened()

Private slot to handle a project being opened.

#### TestingWidget.__resetResults

__resetResults()

Private slot to reset the test results tab and data.

#### TestingWidget.__saveRecent

__saveRecent()

Private method to save the most recently used lists.

#### TestingWidget.__setIdleMode

__setIdleMode()

Private slot to switch the widget to idle mode.

#### TestingWidget.__setRunningMode

__setRunningMode()

Private slot to switch the widget to running mode.

#### TestingWidget.__setStatusLabel

__setStatusLabel(statusText)

Private slot to set the status label to the text sent by the model.

statusText (str)
  text to be shown

#### TestingWidget.__setStoppedMode

__setStoppedMode()

Private slot to switch the widget to stopped mode.

#### TestingWidget.__showCoverageDialog

__showCoverageDialog()

Private slot to show a code coverage dialog for the most recent test run.

#### TestingWidget.__showLogOutput

__showLogOutput()

Private slot to show the output of the most recent test run.

#### TestingWidget.__showSource

__showSource(filename, lineno)

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

filename (str)
  file name of the file to be shown
lineno (int)
  line number to go to in the file

#### TestingWidget.__stopTests

__stopTests()

Private slot to stop the current test run.

#### TestingWidget.__testProcessFinished

__testProcessFinished(results, output)

Private slot to handle the 'testFinished' signal of the executor.

results (list of TestResult)
  list of test result objects (if not sent via the 'testResult' signal
output (str)
  string containing the test process output (if any)

#### TestingWidget.__testRunAboutToBeStarted

__testRunAboutToBeStarted()

Private slot to handle the 'testRunAboutToBeStarted' signal of the executor.

#### TestingWidget.__testRunFinished

__testRunFinished(noTests, duration)

Private slot to handle the 'testRunFinished' signal of the executor.

noTests (int)
  number of tests run by the executor
duration (float)
  time needed in seconds to run the tests

#### TestingWidget.__testStarted

__testStarted(test)

Private slot handling the 'startTest' signal of the executor.

test (tuple of (str, str, str))
  tuple containing the id, name and short description of the tests about to be run

#### TestingWidget.__testsCollectError

__testsCollectError(errors)

Private slot handling the 'collectError' signal of the executor.

errors (list of tuple of (str, str))
  list of tuples containing the test name and a description of the error

#### TestingWidget.__testsCollected

__testsCollected(testNames)

Private slot handling the 'collected' signal of the executor.

testNames (list of tuple of (str, str, str))
  list of tuples containing the test id, the test name and a description of collected tests

#### TestingWidget.__testsStopped

__testsStopped()

Private slot to handle the 'stop' signal of the executor.

#### TestingWidget.__updateButtonBoxButtons

__updateButtonBoxButtons()

Private slot to update the state of the buttons of the button box.

#### TestingWidget.__updateCoverage

__updateCoverage()

Private slot to update the state of the coverage checkbox depending on the selected framework's capabilities.

#### TestingWidget.__updateProgress

__updateProgress()

Private slot update the progress indicators.

#### TestingWidget.clearRecent

clearRecent()

Public slot to clear the recently used lists.

#### TestingWidget.closeEvent

closeEvent(event)

Protected method to handle the close event.

event (QCloseEvent)
  close event

#### TestingWidget.getFailedTests

getFailedTests()

Public method to get the list of failed tests (if any).

Return:
  list of IDs of failed tests

Return Type:
  list of str

#### TestingWidget.getResultsModel

getResultsModel()

Public method to get a reference to the model containing the test result data.

Return:
  reference to the test results model

Return Type:
  TestResultsModel

#### TestingWidget.hasFailedTests

hasFailedTests()

Public method to check for failed tests.

Return:
  flag indicating the existence of failed tests

Return Type:
  bool

#### TestingWidget.on_buttonBox_clicked

on_buttonBox_clicked(button)

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

button (QAbstractButton)
  button that was clicked

#### TestingWidget.on_discoverCheckBox_toggled

on_discoverCheckBox_toggled(checked)

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

checked (bool)
  state of the checkbox

#### TestingWidget.on_frameworkComboBox_currentIndexChanged

on_frameworkComboBox_currentIndexChanged(index)

Private slot handling the selection of a test framework.

index (int)
  index of the selected framework

#### TestingWidget.on_testsuitePicker_aboutToShowPathPickerDialog

on_testsuitePicker_aboutToShowPathPickerDialog()

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

#### TestingWidget.on_venvComboBox_currentIndexChanged

on_venvComboBox_currentIndexChanged(index)

Private slot handling the selection of a virtual environment.

index (int)
  index of the selected environment

#### TestingWidget.on_versionsButton_clicked

on_versionsButton_clicked()

Private slot to show the versions of available plugins.

#### TestingWidget.setTestFile

setTestFile(testFile, forProject=False)

Public slot to set the given test file as the current one.

testFile (str)
  path of the test file
forProject (bool (optional))
  flag indicating that this call is for a project (defaults to False)

#### TestingWidget.startTests

startTests(failedOnly=False)

Public slot to start the test run.

failedOnly (bool)
  flag indicating to run only failed tests

Up

## TestingWidgetModes

Class defining the various modes of the testing widget.

### Derived from

enum.Enum

### Class Attributes

IDLE
RUNNING
STOPPED

### Class Methods

None

### Methods

None

### Static Methods

None

Up

## TestingWindow

Main window class for the standalone dialog.

### Derived from

EricMainWindow

### Class Attributes

None

### Class Methods

None

### Methods

TestingWindow | Constructor
eventFilter | Public method to filter events.

### Static Methods

None

#### TestingWindow (Constructor)

TestingWindow(testfile=None, parent=None)

Constructor

testfile (str)
  file name of the test script to open
parent (QWidget)
  reference to the parent widget

#### TestingWindow.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