-
Notifications
You must be signed in to change notification settings - Fork 96
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
Introduce toolkit-agnostic API for GUI testing #861
Changes from all commits
4c1bddb
bede552
3155ab7
0eeac2a
1d8033f
18cfde3
e5b46a8
73d4859
f25b4d2
cf82e4f
b3754ee
1f9c81e
5b3bdf9
d41d08c
fe0978f
cfed868
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,8 @@ | |
from .constants import OKColor, ErrorColor | ||
from .editor import Editor | ||
|
||
from traitsui.testing.api import BaseSimulator, Disabled, simulate | ||
from traitsui.testing.simulation import DEFAULT_REGISTRY | ||
|
||
# default formatting function (would import from string, but not in Python 3) | ||
capitalize = lambda s: s.capitalize() | ||
|
@@ -299,6 +301,29 @@ def update_autoset_text_object(self): | |
return self.update_text_object(text) | ||
|
||
|
||
@simulate(SimpleEditor, registry=DEFAULT_REGISTRY) | ||
class SimpleEnumEditorSimulator(BaseSimulator): | ||
""" A simulator for testing GUI components with the simple EnumEditor. | ||
|
||
See ``traitsui.testing.api``. | ||
""" | ||
|
||
def click_index(self, index): | ||
self.editor.control.setCurrentIndex(index) | ||
|
||
def set_text(self, text, confirmed=True): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think confirming text entry should be a separate function because it is a separate action for the user - pressing enter or removing focus. And I would say that testing for no change before confirmation, then checking the value after confirmation would be useful for quite a few editors. |
||
if not self.editor.control.isEditable(): | ||
raise Disabled("This combox box is not editable by text.") | ||
|
||
self.editor.control.setEditText(text) | ||
line_edit = self.editor.control.lineEdit() | ||
if line_edit is not None and confirmed: | ||
line_edit.editingFinished.emit() | ||
|
||
def get_text(self): | ||
return self.editor.control.currentText() | ||
|
||
|
||
class RadioEditor(BaseEditor): | ||
""" Enumeration editor, used for the "custom" style, that displays radio | ||
buttons. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from traitsui.testing.ui_tester import UITester # noqa: F401 | ||
from traitsui.testing.exceptions import Disabled # noqa: F401 | ||
from traitsui.testing.simulation import ( | ||
BaseSimulator, | ||
DEFAULT_REGISTRY, | ||
simulate, | ||
SimulatorRegistry, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
class SimulationError(Exception): | ||
""" Raised when simulating user interactions on GUI.""" | ||
pass | ||
|
||
|
||
class Disabled(SimulationError): | ||
""" Raised when a simulation fails because the widget is disabled. | ||
""" | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I don't like having a simulator in between editors - it makes simulators harder to find and is an interruption if just looking at the editors. I think it would be better to have all simulators at the very end of the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point. I will move them down.