-
Notifications
You must be signed in to change notification settings - Fork 95
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
Closed
Closed
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4c1bddb
Draft API for UITester and BaseSimulator
kitchoi bede552
Implement simulation for Qt tests
kitchoi 3155ab7
Add class docstring
kitchoi 0eeac2a
More class docstring
kitchoi 1d8033f
End-of-file new line
kitchoi 18cfde3
More docstrings and cleanup
kitchoi e5b46a8
Implementation for wx tests
kitchoi 73d4859
Revert unrelated change accidentally get mixed in
kitchoi f25b4d2
Improve docstrings
kitchoi cf82e4f
Allow multiple registries
kitchoi b3754ee
Make it easy to contribute alternative simulator implementations
kitchoi 1f9c81e
Add test to demonstrate extending simulator
kitchoi 5b3bdf9
Add requires_one_of decorator
kitchoi d41d08c
Fix test for Qt
kitchoi fe0978f
placeholder is a bad example; use clicking a combobox with an index
kitchoi cfed868
Better imitation of selecting an index
kitchoi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.