Skip to content

Commit b855634

Browse files
aaronayres35Poruri Sai Rahul
andauthored
UI Tester - add IsEnabled query class and implementations for Button Editors (#1320)
* adding IsEnabled Query class and implementations for button editors * adding to tests to exercise use of IsEditable * Apply suggestions from code review Co-authored-by: Poruri Sai Rahul <rporuri@enthought.com> Co-authored-by: Poruri Sai Rahul <rporuri@enthought.com>
1 parent 1aea5f5 commit b855634

File tree

8 files changed

+46
-12
lines changed

8 files changed

+46
-12
lines changed

traitsui/testing/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
from .tester.query import (
8484
DisplayedText,
8585
IsChecked,
86+
IsEnabled,
8687
SelectedText
8788
)
8889

traitsui/testing/tester/_ui_tester_registry/qt4/_traitsui/button_editor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#
99
# Thanks for using Enthought open source!
1010
#
11-
from traitsui.testing.api import DisplayedText, MouseClick
11+
from traitsui.testing.api import DisplayedText, IsEnabled, MouseClick
1212
from traitsui.testing.tester._ui_tester_registry.qt4 import (
1313
_interaction_helpers
1414
)
@@ -31,7 +31,8 @@ def register(registry):
3131
lambda wrapper, _: _interaction_helpers.mouse_click_qwidget(
3232
wrapper._target.control, wrapper.delay)),
3333
(DisplayedText,
34-
lambda wrapper, _: wrapper._target.control.text())
34+
lambda wrapper, _: wrapper._target.control.text()),
35+
(IsEnabled, lambda wrapper, _: wrapper._target.control.isEnabled()),
3536
]
3637

3738
for target_class in [SimpleEditor, CustomEditor]:

traitsui/testing/tester/_ui_tester_registry/qt4/_traitsui/ui_base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# Thanks for using Enthought open source!
1010
#
1111
from traitsui.qt4.ui_base import ButtonEditor
12-
from traitsui.testing.api import DisplayedText, MouseClick
12+
from traitsui.testing.api import DisplayedText, IsEnabled, MouseClick
1313
from traitsui.testing.tester._ui_tester_registry.qt4 import (
1414
_interaction_helpers
1515
)
@@ -30,7 +30,8 @@ def register(registry):
3030
(lambda wrapper, _: _interaction_helpers.mouse_click_qwidget(
3131
wrapper._target.control, wrapper.delay))),
3232
(DisplayedText,
33-
lambda wrapper, _: wrapper._target.control.text())
33+
lambda wrapper, _: wrapper._target.control.text()),
34+
(IsEnabled, lambda wrapper, _: wrapper._target.control.isEnabled()),
3435
]
3536
for interaction_class, handler in handlers:
3637
registry.register_interaction(

traitsui/testing/tester/_ui_tester_registry/wx/_traitsui/button_editor.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import wx
1212

1313
from traitsui.wx.button_editor import SimpleEditor, CustomEditor
14-
from traitsui.testing.api import DisplayedText, MouseClick
14+
from traitsui.testing.api import DisplayedText, IsEnabled, MouseClick
1515
from traitsui.testing.tester._ui_tester_registry.wx import _interaction_helpers
1616

1717

@@ -68,6 +68,12 @@ def register(registry):
6868
handler=lambda wrapper, _: wrapper._target.control.GetLabel()
6969
)
7070

71+
registry.register_interaction(
72+
target_class=SimpleEditor,
73+
interaction_class=IsEnabled,
74+
handler=lambda wrapper, _: wrapper._target.control.IsEnabled()
75+
)
76+
7177
registry.register_interaction(
7278
target_class=CustomEditor,
7379
interaction_class=MouseClick,
@@ -79,3 +85,9 @@ def register(registry):
7985
interaction_class=DisplayedText,
8086
handler=lambda wrapper, _: wrapper._target.control.GetLabel()
8187
)
88+
89+
registry.register_interaction(
90+
target_class=CustomEditor,
91+
interaction_class=IsEnabled,
92+
handler=lambda wrapper, _: wrapper._target.control.IsEnabled()
93+
)

traitsui/testing/tester/_ui_tester_registry/wx/_traitsui/ui_base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# Thanks for using Enthought open source!
1010
#
1111
from traitsui.wx.ui_base import ButtonEditor
12-
from traitsui.testing.api import DisplayedText, MouseClick
12+
from traitsui.testing.api import DisplayedText, IsEnabled, MouseClick
1313
from traitsui.testing.tester._ui_tester_registry.wx import _interaction_helpers
1414

1515

@@ -36,3 +36,9 @@ def register(registry):
3636
interaction_class=DisplayedText,
3737
handler=lambda wrapper, _: wrapper._target.control.GetLabel()
3838
)
39+
40+
registry.register_interaction(
41+
target_class=ButtonEditor,
42+
interaction_class=IsEnabled,
43+
handler=lambda wrapper, _: wrapper._target.control.IsEnabled()
44+
)

traitsui/testing/tester/query.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,12 @@ class IsChecked:
4848
Implementations should return True if checked and False if not.
4949
"""
5050
pass
51+
52+
53+
class IsEnabled:
54+
""" An object representing an interaction to obtain whether a widget is
55+
enabled or not.
56+
57+
Implementations should return True if enabled and False if not.
58+
"""
59+
pass

traitsui/tests/editors/test_button_editor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
)
1212
from traitsui.testing.api import (
1313
DisplayedText,
14+
IsEnabled,
1415
MouseClick,
1516
UITester
1617
)
@@ -116,12 +117,14 @@ def check_button_disabled(self, style):
116117
tester = UITester()
117118
with tester.create_ui(button_text_edit, dict(view=view)) as ui:
118119
button = tester.find_by_name(ui, "play_button")
120+
self.assertFalse(button.inspect(IsEnabled()))
119121

120122
with self.assertTraitDoesNotChange(
121123
button_text_edit, "play_button"):
122124
button.perform(MouseClick())
123125

124126
button_text_edit.button_enabled = True
127+
self.assertTrue(button.inspect(IsEnabled()))
125128
with self.assertTraitChanges(
126129
button_text_edit, "play_button", count=1):
127130
button.perform(MouseClick())

traitsui/tests/test_ui.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
import traitsui
2929
from traitsui.basic_editor_factory import BasicEditorFactory
3030
from traitsui.api import Group, Item, spring, View
31-
from traitsui.testing.tester import command, query
32-
from traitsui.testing.tester.ui_tester import UITester
31+
from traitsui.testing.api import DisplayedText, IsEnabled, MouseClick, UITester
3332
from traitsui.tests._tools import (
3433
BaseTestMixin,
3534
count_calls,
@@ -203,8 +202,9 @@ def test_destroy_after_ok_wx(self):
203202

204203
# press the OK button and close the dialog
205204
ok_button = tester.find_by_id(ui, "OK")
206-
self.assertEqual(ok_button.inspect(query.DisplayedText()), "OK")
207-
ok_button.perform(command.MouseClick())
205+
self.assertEqual(ok_button.inspect(DisplayedText()), "OK")
206+
self.assertTrue(ok_button.inspect(IsEnabled()))
207+
ok_button.perform(MouseClick())
208208

209209
self.assertIsNone(ui.control)
210210
self.assertEqual(control.Destroy._n_calls, 1)
@@ -226,8 +226,9 @@ def test_destroy_after_ok_qt(self):
226226

227227
# press the OK button and close the dialog
228228
ok_button = tester.find_by_id(ui, "OK")
229-
self.assertEqual(ok_button.inspect(query.DisplayedText()), "OK")
230-
ok_button.perform(command.MouseClick())
229+
self.assertEqual(ok_button.inspect(DisplayedText()), "OK")
230+
self.assertTrue(ok_button.inspect(IsEnabled()))
231+
ok_button.perform(MouseClick())
231232

232233
self.assertIsNone(ui.control)
233234
self.assertEqual(control.deleteLater._n_calls, 1)

0 commit comments

Comments
 (0)