traitsui.testing.tester.ui_tester module

Define top-level object(s) to support testing TraitsUI applications.

class traitsui.testing.tester.ui_tester.UITester(*, registries=None, delay=0, auto_process_events=True)[source]

Bases: object

UITester assists testing of GUI applications developed using TraitsUI.

See Testing TraitsUI Applications Section in the User Manual for further details.

Parameters:
  • registries (list of TargetRegistry, optional) – Registries of interaction for different targets, in the order of decreasing priority. If provided, a shallow copy will be made. Additional registries are appended to the list to provide builtin support for TraitsUI UI and editors.

  • delay (int, optional) – Time delay (in ms) in which actions by the tester are performed. Note it is propagated through to created child wrappers. The delay allows visual confirmation test code is working as desired. Defaults to 0.

  • auto_process_events (bool, optional) – Whether to process (cascade) GUI events automatically. Default is True. For tests that launch a modal dialog and rely on a recurring timer to poll if the dialog is closed, it may be necessary to set this flag to false in order to avoid deadlocks. Note that this is propagated through to created child wrappers.

delay

Time delay (in ms) in which actions by the tester are performed. Note it is propagated through to created child wrappers. The delay allows visual confirmation test code is working as desired.

Type:

int

property auto_process_events

Flag to indicate whether to process (cascade) GUI events automatically. This is propagated through to UIWrapper instances created from this tester.

This value can only be set at instantiation.

create_ui(object, ui_kwargs=None)[source]

Context manager to create a UI and dispose it upon exit.

This method does not modify the states of the UITester and is not a requirement for using other methods on the tester.

Parameters:
  • object (HasTraits) – An instance of HasTraits for which a GUI will be created.

  • ui_kwargs (dict or None, optional) – Keyword arguments to be provided to HasTraits.edit_traits. Default is to call edit_traits with no additional keyword arguments.

Yields:

ui (traitsui.ui.UI)

find_by_id(ui, id)[source]

Find the TraitsUI editor with the given identifier and return a new UIWrapper object for further interactions with the editor.

id is typically a value defined on traitsui.item.Item.id or traitsui.group.Group.id. This provides a shortcut to locate a very nested editor in a view.

Parameters:
  • ui (traitsui.ui.UI) – The UI created, e.g. by create_ui.

  • id (str) – Id for finding an item in the UI.

Returns:

wrapper

Return type:

UIWrapper

find_by_name(ui, name)[source]

Find the TraitsUI editor with the given name and return a new UIWrapper object for further interactions with the editor.

name is typically a value defined on traitsui.item.Item.name. This name is passed onto traitsui.ui.UI.get_editors().

Parameters:
  • ui (traitsui.ui.UI) – The UI created, e.g. by create_ui.

  • name (str) – A single name for retrieving a target on a UI.

Returns:

wrapper

Return type:

UIWrapper