Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial UITester API for writing toolkit agnostic tests #1107

Merged
merged 14 commits into from
Aug 19, 2020
Merged
Prev Previous commit
Next Next commit
Lots of renaming; move UIWrapper into its own module
kitchoi committed Aug 18, 2020

Verified

This commit was signed with the committer’s verified signature.
GromNaN Jérôme Tamarelle
commit 78faf30016eb220ed367b2e20c48439c657a2727
37 changes: 0 additions & 37 deletions traitsui/testing/tester/abstract_registry.py

This file was deleted.

4 changes: 2 additions & 2 deletions traitsui/testing/tester/command.py
Original file line number Diff line number Diff line change
@@ -9,8 +9,8 @@
# Thanks for using Enthought open source!
#

""" This module defines action objects that can be passed to
``UserInteractor.perform`` where the actions represent 'commands'.
""" This module defines interaction objects that can be passed to
``UIWrapper.perform`` where the actions represent 'commands'.

Implementations for these actions are expected to produce the
documented side effects without returning any values.
119 changes: 0 additions & 119 deletions traitsui/testing/tester/editor_action_registry.py

This file was deleted.

54 changes: 33 additions & 21 deletions traitsui/testing/tester/exceptions.py
Original file line number Diff line number Diff line change
@@ -10,40 +10,52 @@
#


class SimulationError(Exception):
""" Raised when simulating user interactions on GUI."""
class TesterError(Exception):
""" Custom exception for UITester/UIWrapper. """
pass


class EditorNotFound(LookupError, SimulationError):
""" Raised when an Editor cannot be found by the UI tester or the
interactor.
"""
pass


class ActionNotSupported(SimulationError):
""" Raised when an action is not supported by an interactor.
class InteractionNotSupported(TesterError):
""" Raised when an interaction is not supported by a wrapper.

Parameters
----------
editor_class : subclass of traitsui.editor.Editor
Editor class for which the action is targeting.
action_class : subclass of type
Any class for the action.
target_class : subclass of type
The type of a UI target being operated on.
interaction_class : subclass of type
Any class for the interaction.
supported : list of types
List of supported action types.
List of supported interaction types.
"""

def __init__(self, target_class, interaction_class, supported):
self.target_class = target_class
self.interaction_class = interaction_class
self.supported = supported

def __str__(self):
return (
"No handler is found for target {!r} with interaction {!r}. "
"Supported these: {!r}".format(
self.target_class, self.interaction_class, self.supported
)
)


class LocationNotSupported(TesterError):
""" Raised when attempt to resolve a location on a UI fails
because the location type is not supported.
"""

def __init__(self, editor_class, action_class, supported):
self.editor_class = editor_class
self.action_class = action_class
def __init__(self, target_class, locator_class, supported):
self.target_class = target_class
self.locator_class = locator_class
self.supported = supported

def __str__(self):
return (
"No handler is found for editor {!r} with action {!r}. "
"Location {!r} is not supported for {!r}. "
"Supported these: {!r}".format(
self.editor_class, self.action_class, self.supported
self.locator_class, self.target_class, self.supported
)
)
26 changes: 26 additions & 0 deletions traitsui/testing/tester/locator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
""" This module defines objects for locating nested UI targets, to be
used with ``UIWrapper.locate``.

Implementations for these actions are expected to return a value which is
a UI target where further location resolution or user interaction can be
applied.
"""


class NestedUI:
""" A locator for locating a nested ``traitsui.ui.UI`` object assuming
there is only one. If there are multiple, more location information
needs to have been provided already.
"""
pass


class TargetByName:
""" A locator for locating the next UI target using a name.

Attributes
----------
name : str
"""
def __init__(self, name):
self.name = name
30 changes: 3 additions & 27 deletions traitsui/testing/tester/query.py
Original file line number Diff line number Diff line change
@@ -9,40 +9,16 @@
# Thanks for using Enthought open source!
#

""" This module defines action objects that can be passed to
``UserInteractor.inspect`` where the actions represent 'queries'.
""" This module defines interaction objects that can be passed to
``UIWrapper.inspect`` where the actions represent 'queries'.

Implementations for these actions are expected to return value(s), ideally
without incurring side-effects.
"""


class CustomAction:
""" This is a special action for tests to wrap any arbitrary function
to be used with UITester.

The wrapped function will be called with an instance of ``UserInteractor``
which contains a toolkit specific editor. With that, the wrapped function
is likely toolkit specific.

Attributes
----------
func : callable(UserInteractor) -> any
"""
def __init__(self, func):
self.func = func


class NestedUI:
""" An object representing an action to obtain a nested UI.

Implementations should return an instance of ``traitsui.ui.UI``.
"""
pass


class DisplayedText:
""" An object representing an action to obtain the displayed (echoed)
""" An object representing an interaction to obtain the displayed (echoed)
plain text.

E.g. For a textbox using a password styling, the displayed text should
Loading