diff --git a/traitsui/testing/default_registry.py b/traitsui/testing/default_registry.py index 1cc142591..0ccdd1a96 100644 --- a/traitsui/testing/default_registry.py +++ b/traitsui/testing/default_registry.py @@ -67,12 +67,12 @@ def _get_editor_by_name(ui, name): return editor -def _resolve_ui_editor_by_id(interactor, location): - return _get_editor_by_id(interactor.editor, location.id) +def _resolve_ui_editor_by_id(wrapper, location): + return _get_editor_by_id(wrapper.editor, location.id) -def _resolve_ui_editor_by_name(interactor, location): - return _get_editor_by_name(interactor.editor, location.name) +def _resolve_ui_editor_by_name(wrapper, location): + return _get_editor_by_name(wrapper.editor, location.name) def get_ui_registry(): @@ -92,6 +92,6 @@ def get_ui_registry(): registry.register_location_solver( target_class=UI, locator_class=locator.NestedUI, - solver=lambda interactor, _: interactor.editor, + solver=lambda wrapper, _: wrapper.editor, ) return registry diff --git a/traitsui/testing/exceptions.py b/traitsui/testing/exceptions.py index dbb1be5ea..8cbf751d9 100644 --- a/traitsui/testing/exceptions.py +++ b/traitsui/testing/exceptions.py @@ -11,7 +11,7 @@ class Disabled(SimulationError): class ActionNotSupported(SimulationError): - """ Raised when an action is not supported by an interactor. + """ Raised when an action is not supported by an wrapper. """ def __init__(self, target_class, interaction_class, supported): diff --git a/traitsui/testing/qt4/default_registry.py b/traitsui/testing/qt4/default_registry.py index 427d17f47..a9e8dfee5 100644 --- a/traitsui/testing/qt4/default_registry.py +++ b/traitsui/testing/qt4/default_registry.py @@ -39,43 +39,43 @@ from traitsui.testing.interactor_registry import InteractionRegistry -def resolve_location_simple_editor(interactor, location): - if interactor.editor._dialog_ui is None: - interactor.editor._button.click() - return interactor.editor._dialog_ui +def resolve_location_simple_editor(wrapper, location): + if wrapper.editor._dialog_ui is None: + wrapper.editor._button.click() + return wrapper.editor._dialog_ui -def resolve_location_custom_instance_editor(interactor, location): - return interactor.editor._ui +def resolve_location_custom_instance_editor(wrapper, location): + return wrapper.editor._ui -def resolve_location_range_editor(interactor, location): +def resolve_location_range_editor(wrapper, location): type_to_widget = { - locator.WidgetType.slider: interactor.editor.control.slider, - locator.WidgetType.textbox: interactor.editor.control.text, + locator.WidgetType.slider: wrapper.editor.control.slider, + locator.WidgetType.textbox: wrapper.editor.control.text, } return type_to_widget[location] -def key_sequence_qwidget(interactor, action): - if not interactor.editor.isEnabled(): - raise Disabled("{!r} is disabled.".format(interactor.editor)) - QTest.keyClicks(interactor.editor, action.sequence, delay=interactor.delay) +def key_sequence_qwidget(wrapper, action): + if not wrapper.editor.isEnabled(): + raise Disabled("{!r} is disabled.".format(wrapper.editor)) + QTest.keyClicks(wrapper.editor, action.sequence, delay=wrapper.delay) -def key_press_qwidget(interactor, action): - if not interactor.editor.isEnabled(): - raise Disabled("{!r} is disabled.".format(interactor.editor)) +def key_press_qwidget(wrapper, action): + if not wrapper.editor.isEnabled(): + raise Disabled("{!r} is disabled.".format(wrapper.editor)) helpers.key_press( - interactor.editor, action.key, delay=interactor.delay + wrapper.editor, action.key, delay=wrapper.delay ) -def mouse_click_qwidget(interactor, action): +def mouse_click_qwidget(wrapper, action): QTest.mouseClick( - interactor.editor, + wrapper.editor, QtCore.Qt.LeftButton, - delay=interactor.delay, + delay=wrapper.delay, ) @@ -160,21 +160,21 @@ def get_generic_registry(): registry.register( target_class=QtGui.QPushButton, interaction_class=query.DisplayedText, - handler=lambda interactor, _: interactor.editor.text(), + handler=lambda wrapper, _: wrapper.editor.text(), ) registry.register( target_class=QtGui.QLineEdit, interaction_class=query.DisplayedText, - handler=lambda interactor, _: interactor.editor.displayText(), + handler=lambda wrapper, _: wrapper.editor.displayText(), ) registry.register( target_class=QtGui.QTextEdit, interaction_class=query.DisplayedText, - handler=lambda interactor, _: interactor.editor.toPlainText(), + handler=lambda wrapper, _: wrapper.editor.toPlainText(), ) registry.register( target_class=QtGui.QLabel, interaction_class=query.DisplayedText, - handler=lambda interactor, _: interactor.editor.text(), + handler=lambda wrapper, _: wrapper.editor.text(), ) return registry diff --git a/traitsui/testing/qt4/implementation/button_editor.py b/traitsui/testing/qt4/implementation/button_editor.py index 01c305782..4eab50873 100644 --- a/traitsui/testing/qt4/implementation/button_editor.py +++ b/traitsui/testing/qt4/implementation/button_editor.py @@ -10,10 +10,10 @@ def register(registry): registry.register_location_solver( target_class=SimpleEditor, locator_class=locator.DefaultTarget, - solver=lambda interactor, _: interactor.editor.control, + solver=lambda wrapper, _: wrapper.editor.control, ) registry.register_location_solver( target_class=CustomEditor, locator_class=locator.DefaultTarget, - solver=lambda interactor, _: interactor.editor.control, + solver=lambda wrapper, _: wrapper.editor.control, ) diff --git a/traitsui/testing/qt4/implementation/check_list_editor.py b/traitsui/testing/qt4/implementation/check_list_editor.py index 7f516e550..57f1efc9f 100644 --- a/traitsui/testing/qt4/implementation/check_list_editor.py +++ b/traitsui/testing/qt4/implementation/check_list_editor.py @@ -11,10 +11,10 @@ def __init__(self, editor, index): self.index = index @classmethod - def from_location_index(cls, interactor, location): + def from_location_index(cls, wrapper, location): # Conform to the call signature specified in the register return cls( - editor=interactor.editor, + editor=wrapper.editor, index=location.index, ) @@ -28,8 +28,8 @@ def register(cls, registry): registry.register( target_class=cls, interaction_class=command.MouseClick, - handler=lambda interactor, _: interactor.editor.mouse_click( - delay=interactor.delay, + handler=lambda wrapper, _: wrapper.editor.mouse_click( + delay=wrapper.delay, ) ) diff --git a/traitsui/testing/qt4/implementation/enum_editor.py b/traitsui/testing/qt4/implementation/enum_editor.py index c251970c2..9959969ff 100644 --- a/traitsui/testing/qt4/implementation/enum_editor.py +++ b/traitsui/testing/qt4/implementation/enum_editor.py @@ -15,9 +15,9 @@ def __init__(self, editor, index): self.index = index @classmethod - def from_location(cls, interactor, location): + def from_location(cls, wrapper, location): return cls( - editor=interactor.editor, + editor=wrapper.editor, index=location.index, ) @@ -31,8 +31,8 @@ def register(cls, registry): registry.register( target_class=cls, interaction_class=command.MouseClick, - handler=lambda interactor, _: ( - interactor.editor.mouse_click(delay=interactor.delay) + handler=lambda wrapper, _: ( + wrapper.editor.mouse_click(delay=wrapper.delay) ) ) @@ -54,9 +54,9 @@ def __init__(self, editor, index): self.index = index @classmethod - def from_location(cls, interactor, location): + def from_location(cls, wrapper, location): return cls( - editor=interactor.editor, + editor=wrapper.editor, index=location.index, ) @@ -70,8 +70,8 @@ def register(cls, registry): registry.register( target_class=cls, interaction_class=command.MouseClick, - handler=lambda interactor, _: interactor.editor.mouse_click( - delay=interactor.delay, + handler=lambda wrapper, _: wrapper.editor.mouse_click( + delay=wrapper.delay, ), ) @@ -99,15 +99,15 @@ def register(cls, registry): registry.register( target_class=cls, interaction_class=command.MouseClick, - handler=lambda interactor, _: interactor.editor.mouse_click( - delay=interactor.delay, + handler=lambda wrapper, _: wrapper.editor.mouse_click( + delay=wrapper.delay, ), ) @classmethod - def from_location(cls, interactor, location): + def from_location(cls, wrapper, location): return cls( - editor=interactor.editor, + editor=wrapper.editor, index=location.index, ) diff --git a/traitsui/testing/qt4/implementation/group_editor.py b/traitsui/testing/qt4/implementation/group_editor.py index 577a91b1d..e4189b745 100644 --- a/traitsui/testing/qt4/implementation/group_editor.py +++ b/traitsui/testing/qt4/implementation/group_editor.py @@ -19,9 +19,9 @@ def mouse_click(self, delay=0): self.editor.container.setCurrentIndex(self.index) @classmethod - def from_location_index(cls, interactor, location): + def from_location_index(cls, wrapper, location): return cls( - editor=interactor.editor, index=location.index, + editor=wrapper.editor, index=location.index, ) @@ -34,7 +34,7 @@ def register_tabbed_fold_group_editor(registry): registry.register( target_class=_IndexedTabbedFoldGroupEditor, interaction_class=command.MouseClick, - handler=lambda interactor, _: ( - interactor.editor.mouse_click(delay=interactor.delay) + handler=lambda wrapper, _: ( + wrapper.editor.mouse_click(delay=wrapper.delay) ) ) diff --git a/traitsui/testing/qt4/implementation/list_editor.py b/traitsui/testing/qt4/implementation/list_editor.py index b5528d4b6..db6134205 100644 --- a/traitsui/testing/qt4/implementation/list_editor.py +++ b/traitsui/testing/qt4/implementation/list_editor.py @@ -19,11 +19,11 @@ def __init__(self, editor, index): self.index = index @classmethod - def from_location(cls, interactor, location): + def from_location(cls, wrapper, location): # Raise IndexError early - interactor.editor._uis[location.index] + wrapper.editor._uis[location.index] return cls( - editor=interactor.editor, + editor=wrapper.editor, index=location.index, ) @@ -37,7 +37,7 @@ def register(cls, registry): registry.register_location_solver( target_class=cls, locator_class=locator.NestedUI, - solver=lambda interactor, _: interactor.editor.get_nested_ui(), + solver=lambda wrapper, _: wrapper.editor.get_nested_ui(), ) registry_helper.register_find_by_in_nested_ui( registry=registry, @@ -46,8 +46,8 @@ def register(cls, registry): registry.register( target_class=cls, interaction_class=command.MouseClick, - handler=lambda interactor, _: ( - interactor.editor.mouse_click(delay=interactor.delay) + handler=lambda wrapper, _: ( + wrapper.editor.mouse_click(delay=wrapper.delay) ), ) @@ -67,9 +67,9 @@ def __init__(self, editor, index): self.index = index @classmethod - def from_location(cls, interactor, location): + def from_location(cls, wrapper, location): return cls( - editor=interactor.editor, + editor=wrapper.editor, index=location.index, ) @@ -83,7 +83,7 @@ def register(cls, registry): registry.register_location_solver( target_class=cls, locator_class=locator.NestedUI, - solver=lambda interactor, _: interactor.editor._get_nested_ui(), + solver=lambda wrapper, _: wrapper.editor._get_nested_ui(), ) registry_helper.register_find_by_in_nested_ui( registry=registry, diff --git a/traitsui/testing/qt4/implementation/table_editor.py b/traitsui/testing/qt4/implementation/table_editor.py index 7968de948..a88a399c3 100644 --- a/traitsui/testing/qt4/implementation/table_editor.py +++ b/traitsui/testing/qt4/implementation/table_editor.py @@ -10,9 +10,9 @@ def __init__(self, editor, cell): self.cell = cell @classmethod - def from_location(cls, interactor, location): + def from_location(cls, wrapper, location): return cls( - editor=interactor.editor, + editor=wrapper.editor, cell=location, ) @@ -26,31 +26,31 @@ def register(cls, registry): registry.register( target_class=cls, interaction_class=command.MouseClick, - handler=lambda interactor, _: interactor.editor._mouse_click( - delay=interactor.delay, + handler=lambda wrapper, _: wrapper.editor._mouse_click( + delay=wrapper.delay, ), ) registry.register( target_class=cls, interaction_class=command.KeySequence, - handler=lambda interactor, action: interactor.editor._key_sequence( + handler=lambda wrapper, action: wrapper.editor._key_sequence( sequence=action.sequence, - delay=interactor.delay, + delay=wrapper.delay, ), ) registry.register( target_class=cls, interaction_class=command.KeyClick, - handler=lambda interactor, action: interactor.editor._key_press( + handler=lambda wrapper, action: wrapper.editor._key_press( key=action.key, - delay=interactor.delay, + delay=wrapper.delay, ), ) registry.register( target_class=cls, interaction_class=query.DisplayedText, - handler=lambda interactor, _: ( - interactor.editor._get_displayed_text() + handler=lambda wrapper, _: ( + wrapper.editor._get_displayed_text() ), ) diff --git a/traitsui/testing/qt4/implementation/text_editor.py b/traitsui/testing/qt4/implementation/text_editor.py index 82f779b91..886e7c83b 100644 --- a/traitsui/testing/qt4/implementation/text_editor.py +++ b/traitsui/testing/qt4/implementation/text_editor.py @@ -10,15 +10,15 @@ def register(registry): registry.register_location_solver( target_class=SimpleEditor, locator_class=locator.DefaultTarget, - solver=lambda interactor, _: interactor.editor.control, + solver=lambda wrapper, _: wrapper.editor.control, ) registry.register_location_solver( target_class=CustomEditor, locator_class=locator.DefaultTarget, - solver=lambda interactor, _: interactor.editor.control, + solver=lambda wrapper, _: wrapper.editor.control, ) registry.register_location_solver( target_class=ReadonlyEditor, locator_class=locator.DefaultTarget, - solver=lambda interactor, _: interactor.editor.control, + solver=lambda wrapper, _: wrapper.editor.control, ) diff --git a/traitsui/testing/qt4/implementation/tree_editor.py b/traitsui/testing/qt4/implementation/tree_editor.py index 62d9d97fe..24a7350cf 100644 --- a/traitsui/testing/qt4/implementation/tree_editor.py +++ b/traitsui/testing/qt4/implementation/tree_editor.py @@ -11,9 +11,9 @@ def __init__(self, editor, node): self.node = node @classmethod - def from_location(cls, interactor, location): + def from_location(cls, wrapper, location): return cls( - editor=interactor.editor, + editor=wrapper.editor, node=location, ) @@ -27,38 +27,38 @@ def register(cls, registry): registry.register( target_class=cls, interaction_class=command.MouseClick, - handler=lambda interactor, _: interactor.editor._mouse_click( - delay=interactor.delay, + handler=lambda wrapper, _: wrapper.editor._mouse_click( + delay=wrapper.delay, ), ) registry.register( target_class=cls, interaction_class=command.MouseDClick, - handler=lambda interactor, _: interactor.editor._mouse_dclick( - delay=interactor.delay, + handler=lambda wrapper, _: wrapper.editor._mouse_dclick( + delay=wrapper.delay, ), ) registry.register( target_class=cls, interaction_class=command.KeySequence, - handler=lambda interactor, action: interactor.editor._key_sequence( + handler=lambda wrapper, action: wrapper.editor._key_sequence( sequence=action.sequence, - delay=interactor.delay, + delay=wrapper.delay, ), ) registry.register( target_class=cls, interaction_class=command.KeyClick, - handler=lambda interactor, action: interactor.editor._key_press( + handler=lambda wrapper, action: wrapper.editor._key_press( key=action.key, - delay=interactor.delay, + delay=wrapper.delay, ), ) registry.register( target_class=cls, interaction_class=query.DisplayedText, - handler=lambda interactor, _: ( - interactor.editor._get_displayed_text() + handler=lambda wrapper, _: ( + wrapper.editor._get_displayed_text() ), ) @@ -113,7 +113,7 @@ def register(registry): registry.register_location_solver( target_class=SimpleEditor, locator_class=locator.NestedUI, - solver=lambda interactor, _: interactor.editor._editor._node_ui, + solver=lambda wrapper, _: wrapper.editor._editor._node_ui, ) registry_helper.register_find_by_in_nested_ui( registry=registry, diff --git a/traitsui/testing/qt4/implementation/ui_base.py b/traitsui/testing/qt4/implementation/ui_base.py index 4a741eaf6..e03b572c0 100644 --- a/traitsui/testing/qt4/implementation/ui_base.py +++ b/traitsui/testing/qt4/implementation/ui_base.py @@ -6,5 +6,5 @@ def register(registry): registry.register_location_solver( target_class=ButtonEditor, locator_class=locator.DefaultTarget, - solver=lambda interactor, _: interactor.editor.control, + solver=lambda wrapper, _: wrapper.editor.control, ) diff --git a/traitsui/testing/qt4/tests/test_default_registry.py b/traitsui/testing/qt4/tests/test_default_registry.py index 5e09f151f..9f4cef2c4 100644 --- a/traitsui/testing/qt4/tests/test_default_registry.py +++ b/traitsui/testing/qt4/tests/test_default_registry.py @@ -31,12 +31,12 @@ def test_mouse_click(self): click_slot = mock.Mock() button.clicked.connect(click_slot) - interactor = interactor = UIWrapper( + wrapper = wrapper = UIWrapper( editor=button, registries=[default_registry.get_default_registry()], ) - interactor.perform(command.MouseClick()) + wrapper.perform(command.MouseClick()) self.assertEqual(click_slot.call_count, 1) @@ -47,7 +47,7 @@ def test_mouse_click_disabled(self): click_slot = mock.Mock() button.clicked.connect(click_slot) - interactor = interactor = UIWrapper( + wrapper = wrapper = UIWrapper( editor=button, registries=[default_registry.get_default_registry()], ) @@ -55,7 +55,7 @@ def test_mouse_click_disabled(self): # when # clicking won't fail, it just does not do anything. # This is consistent with the actual UI. - interactor.perform(command.MouseClick()) + wrapper.perform(command.MouseClick()) # then self.assertEqual(click_slot.call_count, 0) @@ -64,11 +64,11 @@ def test_key_sequence(self): textbox = QtGui.QLineEdit() change_slot = mock.Mock() textbox.textEdited.connect(change_slot) - interactor = create_interactor(editor=textbox) + wrapper = create_interactor(editor=textbox) # when default_registry.key_sequence_qwidget( - interactor, command.KeySequence("abc")) + wrapper, command.KeySequence("abc")) # then self.assertEqual(textbox.text(), "abc") @@ -78,28 +78,28 @@ def test_key_sequence(self): def test_key_sequence_disabled(self): textbox = QtGui.QLineEdit() textbox.setEnabled(False) - interactor = create_interactor(editor=textbox) + wrapper = create_interactor(editor=textbox) # then # this will fail, because one should not be allowed to set # cursor on the widget to type anything with self.assertRaises(Disabled): default_registry.key_sequence_qwidget( - interactor, command.KeySequence("abc")) + wrapper, command.KeySequence("abc")) def test_key_press(self): textbox = QtGui.QLineEdit() change_slot = mock.Mock() textbox.editingFinished.connect(change_slot) - interactor = create_interactor(editor=textbox) + wrapper = create_interactor(editor=textbox) # sanity check default_registry.key_sequence_qwidget( - interactor, command.KeySequence("abc")) + wrapper, command.KeySequence("abc")) self.assertEqual(change_slot.call_count, 0) default_registry.key_press_qwidget( - interactor, command.KeyClick("Enter")) + wrapper, command.KeyClick("Enter")) self.assertEqual(change_slot.call_count, 1) def test_key_press_disabled(self): @@ -107,11 +107,11 @@ def test_key_press_disabled(self): textbox.setEnabled(False) change_slot = mock.Mock() textbox.editingFinished.connect(change_slot) - interactor = create_interactor(editor=textbox) + wrapper = create_interactor(editor=textbox) with self.assertRaises(Disabled): default_registry.key_press_qwidget( - interactor, command.KeyClick("Enter")) + wrapper, command.KeyClick("Enter")) self.assertEqual(change_slot.call_count, 0) def test_mouse_click_combobox(self): diff --git a/traitsui/testing/registry_helper.py b/traitsui/testing/registry_helper.py index 576581927..a1d3b31f5 100644 --- a/traitsui/testing/registry_helper.py +++ b/traitsui/testing/registry_helper.py @@ -1,13 +1,13 @@ from traitsui.testing import locator -def find_by_id_in_nested_ui(interactor, location): - new_interactor = interactor.locate(locator.NestedUI()) +def find_by_id_in_nested_ui(wrapper, location): + new_interactor = wrapper.locate(locator.NestedUI()) return new_interactor.find_by_id(location.id).editor -def find_by_name_in_nested_ui(interactor, location): - new_interactor = interactor.locate(locator.NestedUI()) +def find_by_name_in_nested_ui(wrapper, location): + new_interactor = wrapper.locate(locator.NestedUI()) return new_interactor.find_by_name(location.name).editor diff --git a/traitsui/testing/tests/test_ui_tester.py b/traitsui/testing/tests/test_ui_tester.py index 93b228e49..f3d549dcd 100644 --- a/traitsui/testing/tests/test_ui_tester.py +++ b/traitsui/testing/tests/test_ui_tester.py @@ -87,29 +87,29 @@ class BadAction: pass -def raise_error(interactor, action): +def raise_error(wrapper, action): raise ZeroDivisionError() if is_qt(): from traitsui.qt4.button_editor import SimpleEditor as SimpleButtonEditor - def click_n_times(interactor, action): + def click_n_times(wrapper, action): for _ in range(action.n_times): - if not interactor.editor.control.isEnabled(): + if not wrapper.editor.control.isEnabled(): raise Disabled("Button is disabled.") - interactor.editor.control.click() + wrapper.editor.control.click() - def is_enabled(interactor, action): - return interactor.editor.control.isEnabled() + def is_enabled(wrapper, action): + return wrapper.editor.control.isEnabled() if is_wx(): from traitsui.wx.button_editor import SimpleEditor as SimpleButtonEditor - def click_n_times(interactor, action): # noqa: F811 + def click_n_times(wrapper, action): # noqa: F811 import wx - control = interactor.editor.control + control = wrapper.editor.control if not control.IsEnabled(): raise Disabled("Button is disabled.") event = wx.CommandEvent(wx.EVT_BUTTON.typeId, control.GetId()) @@ -117,8 +117,8 @@ def click_n_times(interactor, action): # noqa: F811 for _ in range(action.n_times): wx.PostEvent(control, event) - def is_enabled(interactor, action): # noqa: F811 - return interactor.editor.control.IsEnabled() + def is_enabled(wrapper, action): # noqa: F811 + return wrapper.editor.control.IsEnabled() def get_local_registry(): @@ -147,7 +147,7 @@ class TestUITesterSimulate(unittest.TestCase): """ def check_command_propagated_to_nested_ui(self, style): - # the default interactor for the instance editor is used, and then + # the default wrapper for the instance editor is used, and then # the custom simulation on the button is used. order = Order() view = get_view_with_instance_editor(style) @@ -162,17 +162,17 @@ def check_command_propagated_to_nested_ui(self, style): self.assertEqual(order.submit_n_events, 3) def test_command_custom_interactor_with_simple_instance_editor(self): - # Check command is propagated by the interactor get_ui for + # Check command is propagated by the wrapper get_ui for # simple instance editor. self.check_command_propagated_to_nested_ui("simple") def test_command_custom_interactor_with_custom_instance_editor(self): - # Check command is propagated by the interactor get_ui for + # Check command is propagated by the wrapper get_ui for # custom instance editor. self.check_command_propagated_to_nested_ui("custom") def check_query_propagated_to_nested_ui(self, style): - # the default interactor for the instance editor is used, and then + # the default wrapper for the instance editor is used, and then # the custom simulation on the button is used. order = Order() view = get_view_with_instance_editor(style, enabled_when="False") @@ -187,12 +187,12 @@ def check_query_propagated_to_nested_ui(self, style): self.assertIs(actual, False) def test_query_custom_interactor_with_simple_instance_editor(self): - # Check query is propagated by the interactor get_ui for + # Check query is propagated by the wrapper get_ui for # simple instance editor. self.check_query_propagated_to_nested_ui("simple") def test_query_custom_interactor_with_custom_instance_editor(self): - # Check query is propagated by the interactor get_ui for + # Check query is propagated by the wrapper get_ui for # custom instance editor. self.check_query_propagated_to_nested_ui("custom") @@ -266,7 +266,7 @@ def test_backward_compatibility_when_new_location_introduced(self): new_registry.register_location_solver( target_class=SimpleButtonEditor, locator_class=locator.DefaultTarget, - solver=lambda interactor, _: interactor.editor.control, + solver=lambda wrapper, _: wrapper.editor.control, ) tester = UITester([new_registry, registry]) with tester.create_ui(order, dict(view=view)) as ui: @@ -297,10 +297,10 @@ class TestUITesterFind(unittest.TestCase): def test_create_ui_interactor(self): tester = UITester(delay=1000) with tester.create_ui(Order()) as ui: - interactor = tester._get_ui_interactor(ui) - self.assertIs(interactor.editor, ui) - self.assertEqual(interactor.registries, tester._registries) - self.assertEqual(interactor.delay, tester.delay) + wrapper = tester._get_ui_interactor(ui) + self.assertIs(wrapper.editor, ui) + self.assertEqual(wrapper.registries, tester._registries) + self.assertEqual(wrapper.delay, tester.delay) def test_ui_interactor_locate_by_name(self): tester = UITester() @@ -367,10 +367,10 @@ def test_find_by_id(self): item2 = Item("submit_button", id="item2") view = View(item1, item2) with tester.create_ui(Order(), dict(view=view)) as ui: - interactor = tester.find_by_id(ui, "item2") - self.assertIs(interactor.editor.item, item2) - self.assertEqual(interactor.registries, tester._registries) - self.assertEqual(interactor.delay, tester.delay) + wrapper = tester.find_by_id(ui, "item2") + self.assertIs(wrapper.editor.item, item2) + self.assertEqual(wrapper.registries, tester._registries) + self.assertEqual(wrapper.delay, tester.delay) def test_find_by_id_multiple(self): # The uniqueness is not enforced. The first one is returned. @@ -380,8 +380,8 @@ def test_find_by_id_multiple(self): item3 = Item("submit_button", id="item2") view = View(item1, item2, item3) with tester.create_ui(Order(), dict(view=view)) as ui: - interactor = tester.find_by_id(ui, "item2") - self.assertIs(interactor.editor.item, item2) + wrapper = tester.find_by_id(ui, "item2") + self.assertIs(wrapper.editor.item, item2) def test_find_by_id_in_nested(self): order = Order() @@ -405,10 +405,10 @@ def test_find_by_name(self): item2 = Item("submit_n_events", id="item2") view = View(item1, item2) with tester.create_ui(Order(), dict(view=view)) as ui: - interactor = tester.find_by_name(ui, "submit_n_events") - self.assertIs(interactor.editor.item, item2) - self.assertEqual(interactor.registries, tester._registries) - self.assertEqual(interactor.delay, tester.delay) + wrapper = tester.find_by_name(ui, "submit_n_events") + self.assertIs(wrapper.editor.item, item2) + self.assertEqual(wrapper.registries, tester._registries) + self.assertEqual(wrapper.delay, tester.delay) def test_find_by_name_in_nested(self): order = Order() @@ -434,7 +434,7 @@ class TestUITesterLocate(unittest.TestCase): def setUp(self): self.target_class = FakeTarget self.registry = InteractionRegistry() - self.interactor = UIWrapper( + self.wrapper = UIWrapper( editor=FakeTarget(), registries=[self.registry], ) @@ -443,7 +443,7 @@ def test_locate_with_resolved_target(self): target = (1, 2, 3) - def resolve_target(interactor, location): + def resolve_target(wrapper, location): return target self.registry.register_location_solver( @@ -452,7 +452,7 @@ def resolve_target(interactor, location): solver=resolve_target, ) - new_location = self.interactor.locate(0) + new_location = self.wrapper.locate(0) self.assertIs(new_location.editor, target) def test_locate_with_unknown_location(self): @@ -463,4 +463,4 @@ def test_locate_with_unknown_location(self): solver=mock.Mock(), ) with self.assertRaises(LocationNotSupported): - self.interactor.locate("123") + self.wrapper.locate("123") diff --git a/traitsui/testing/ui_tester.py b/traitsui/testing/ui_tester.py index 97e85682a..8d85e4ce6 100644 --- a/traitsui/testing/ui_tester.py +++ b/traitsui/testing/ui_tester.py @@ -95,9 +95,9 @@ class MyAction: class MyEditor(Editor): ... - def click(interactor, action): - # ``interactor`` is an instance of UIWrapper - interactor.editor.control.click() + def click(wrapper, action): + # ``wrapper`` is an instance of UIWrapper + wrapper.editor.control.click() my_registry = InteractionRegistry() my_registry.register( @@ -188,7 +188,7 @@ def find_by_name(self, ui, name): Returns ------- - interactor : BaseUserInteractor + wrapper : BaseUserInteractor """ return ( self._get_ui_interactor(ui).locate(locator.TargetByName(name=name)) @@ -209,7 +209,7 @@ def find_by_id(self, ui, id): Returns ------- - interactor : BaseUserInteractor + wrapper : BaseUserInteractor """ return self._get_ui_interactor(ui).locate(locator.TargetById(id=id)) @@ -263,7 +263,7 @@ def perform(self, action): e.g. ``traitsui.testing.command.MouseClick`` """ self._resolve( - lambda interactor: interactor._perform_or_inspect(action), + lambda wrapper: wrapper._perform_or_inspect(action), catches=ActionNotSupported, ) @@ -279,12 +279,12 @@ def inspect(self, action): e.g. ``traitsui.testing.query.DisplayedText`` """ return self._resolve( - lambda interactor: interactor._perform_or_inspect(action), + lambda wrapper: wrapper._perform_or_inspect(action), catches=ActionNotSupported, ) def locate(self, location): - """ Return a new interactor for performing user actions on a specific + """ Return a new wrapper for performing user actions on a specific location specified. Implementations must validate the type of the location given. @@ -296,7 +296,7 @@ def locate(self, location): location : Location """ return self._resolve( - lambda interactor: interactor._new_from_location(location), + lambda wrapper: wrapper._new_from_location(location), catches=LocationNotSupported, ) @@ -312,7 +312,7 @@ def find_by_name(self, name): Returns ------- - interactor : UIWrapper + wrapper : UIWrapper """ return self.locate(locator.TargetByName(name=name)) @@ -328,12 +328,12 @@ def find_by_id(self, id): Returns ------- - interactor : UIWrapper + wrapper : UIWrapper """ return self.locate(locator.TargetById(id=id)) def _resolve(self, function, catches): - """ Execute the given callable with this interactor, if fails, try + """ Execute the given callable with this wrapper, if fails, try again with the default target (if there is one). Parameters diff --git a/traitsui/testing/wx/default_registry.py b/traitsui/testing/wx/default_registry.py index 763189aea..23a7d4860 100644 --- a/traitsui/testing/wx/default_registry.py +++ b/traitsui/testing/wx/default_registry.py @@ -28,12 +28,12 @@ ) -def resolve_location_simple_editor(interactor, _): - return interactor.editor.edit_instance(None) +def resolve_location_simple_editor(wrapper, _): + return wrapper.editor.edit_instance(None) -def resolve_location_custom_instance_editor(interactor, _): - return interactor.editor._ui +def resolve_location_custom_instance_editor(wrapper, _): + return wrapper.editor._ui def get_default_registry(): @@ -70,38 +70,38 @@ def get_generic_registry(): registry.register( target_class=wx.TextCtrl, interaction_class=command.KeyClick, - handler=lambda interactor, action: ( + handler=lambda wrapper, action: ( helpers.key_press_text_ctrl( - control=interactor.editor, + control=wrapper.editor, key=action.key, - delay=interactor.delay, + delay=wrapper.delay, ) ), ) registry.register( target_class=wx.TextCtrl, interaction_class=command.KeySequence, - handler=lambda interactor, action: ( + handler=lambda wrapper, action: ( helpers.key_sequence_text_ctrl( - control=interactor.editor, + control=wrapper.editor, sequence=action.sequence, - delay=interactor.delay, + delay=wrapper.delay, ) ), ) registry.register( target_class=wx.StaticText, interaction_class=query.DisplayedText, - handler=lambda interactor, action: ( - interactor.editor.GetLabel() + handler=lambda wrapper, action: ( + wrapper.editor.GetLabel() ), ) registry.register( target_class=wx.Button, interaction_class=command.MouseClick, - handler=lambda interactor, _: ( + handler=lambda wrapper, _: ( helpers.mouse_click_button( - control=interactor.editor, delay=interactor.delay, + control=wrapper.editor, delay=wrapper.delay, ) ) ) diff --git a/traitsui/testing/wx/implementation/button_editor.py b/traitsui/testing/wx/implementation/button_editor.py index 2296233c3..814515598 100644 --- a/traitsui/testing/wx/implementation/button_editor.py +++ b/traitsui/testing/wx/implementation/button_editor.py @@ -7,5 +7,5 @@ def register(registry): registry.register_location_solver( target_class=SimpleEditor, locator_class=locator.DefaultTarget, - solver=lambda interactor, _: interactor.editor.control, + solver=lambda wrapper, _: wrapper.editor.control, ) diff --git a/traitsui/testing/wx/implementation/range_editor.py b/traitsui/testing/wx/implementation/range_editor.py index f06a200e5..4ff7a2497 100644 --- a/traitsui/testing/wx/implementation/range_editor.py +++ b/traitsui/testing/wx/implementation/range_editor.py @@ -18,9 +18,9 @@ def register(cls, registry): registry.register( target_class=cls, interaction_class=command.KeyClick, - handler=lambda interactor, action: ( - interactor.editor.key_press( - key=action.key, delay=interactor.delay, + handler=lambda wrapper, action: ( + wrapper.editor.key_press( + key=action.key, delay=wrapper.delay, ) ) ) @@ -33,13 +33,13 @@ def key_press(self, key, delay=0): ) -def resolve_location_simple_slider(interactor, location): +def resolve_location_simple_slider(wrapper, location): if location == locator.WidgetType.slider: return _SimpleSliderEditorWithSlider( - editor=interactor.editor, + editor=wrapper.editor, ) if location == locator.WidgetType.textbox: - return interactor.editor.control.text + return wrapper.editor.control.text raise NotImplementedError() diff --git a/traitsui/testing/wx/implementation/text_editor.py b/traitsui/testing/wx/implementation/text_editor.py index 81ef7e0c7..c858e3f2b 100644 --- a/traitsui/testing/wx/implementation/text_editor.py +++ b/traitsui/testing/wx/implementation/text_editor.py @@ -6,10 +6,10 @@ def register(registry): registry.register_location_solver( target_class=SimpleEditor, locator_class=locator.DefaultTarget, - solver=lambda interactor, _: interactor.editor.control, + solver=lambda wrapper, _: wrapper.editor.control, ) registry.register_location_solver( target_class=ReadonlyEditor, locator_class=locator.DefaultTarget, - solver=lambda interactor, _: interactor.editor.control, + solver=lambda wrapper, _: wrapper.editor.control, ) diff --git a/traitsui/testing/wx/implementation/ui_base.py b/traitsui/testing/wx/implementation/ui_base.py index 4a576c339..d0e174127 100644 --- a/traitsui/testing/wx/implementation/ui_base.py +++ b/traitsui/testing/wx/implementation/ui_base.py @@ -6,5 +6,5 @@ def register(registry): registry.register_location_solver( target_class=ButtonEditor, locator_class=locator.DefaultTarget, - solver=lambda interactor, _: interactor.editor.control, + solver=lambda wrapper, _: wrapper.editor.control, ) diff --git a/traitsui/testing/wx/tests/test_default_registry.py b/traitsui/testing/wx/tests/test_default_registry.py index ccb8eb49d..e6db55a53 100644 --- a/traitsui/testing/wx/tests/test_default_registry.py +++ b/traitsui/testing/wx/tests/test_default_registry.py @@ -37,13 +37,13 @@ def test_mouse_click(self): handler = mock.Mock() button = wx.Button(self.frame) button.Bind(wx.EVT_BUTTON, handler) - interactor = UIWrapper( + wrapper = UIWrapper( editor=button, registries=[default_registry.get_default_registry()], ) # when - interactor.perform(command.MouseClick()) + wrapper.perform(command.MouseClick()) # then self.assertEqual(handler.call_count, 1) @@ -53,13 +53,13 @@ def test_mouse_click_disabled_button(self): button = wx.Button(self.frame) button.Bind(wx.EVT_BUTTON, handler) button.Enable(False) - interactor = UIWrapper( + wrapper = UIWrapper( editor=button, registries=[default_registry.get_default_registry()], ) # when - interactor.perform(command.MouseClick()) + wrapper.perform(command.MouseClick()) # then self.assertEqual(handler.call_count, 0) diff --git a/traitsui/tests/editors/test_button_editor.py b/traitsui/tests/editors/test_button_editor.py index 2aeefe4d6..38aa9b537 100644 --- a/traitsui/tests/editors/test_button_editor.py +++ b/traitsui/tests/editors/test_button_editor.py @@ -55,7 +55,7 @@ class ButtonTextEdit(HasTraits): LOCAL_REGISTRY.register( target_class=target_class, interaction_class=query.DisplayedText, - handler=lambda interactor, _: interactor.editor.control.GetLabel(), + handler=lambda wrapper, _: wrapper.editor.control.GetLabel(), ) elif is_qt(): from traitsui.qt4.button_editor import CustomEditor, SimpleEditor @@ -63,7 +63,7 @@ class ButtonTextEdit(HasTraits): LOCAL_REGISTRY.register( target_class=target_class, interaction_class=query.DisplayedText, - handler=lambda interactor, _: interactor.editor.control.text(), + handler=lambda wrapper, _: wrapper.editor.control.text(), ) diff --git a/traitsui/tests/editors/test_table_editor.py b/traitsui/tests/editors/test_table_editor.py index c8d4eaed5..6b73c737e 100644 --- a/traitsui/tests/editors/test_table_editor.py +++ b/traitsui/tests/editors/test_table_editor.py @@ -500,12 +500,12 @@ def test_table_editor_select_row_index_with_tester(self): ) tester = UITester() with tester.create_ui(object_list, dict(view=view)) as ui: - interactor = tester.find_by_name(ui, "values") + wrapper = tester.find_by_name(ui, "values") - interactor.locate(Cell(5, 0)).perform(MouseClick()) + wrapper.locate(Cell(5, 0)).perform(MouseClick()) self.assertEqual(object_list.selected.value, str(5 ** 2)) - interactor.locate(Cell(6, 0)).perform(MouseClick()) + wrapper.locate(Cell(6, 0)).perform(MouseClick()) self.assertEqual(object_list.selected.value, str(6 ** 2)) @requires_toolkit([ToolkitName.qt, ToolkitName.wx]) @@ -530,19 +530,19 @@ def test_table_editor_modify_cell_with_tester(self): ) tester = UITester() with tester.create_ui(object_list, dict(view=view)) as ui: - interactor = tester.find_by_name(ui, "values").locate(Cell(5, 0)) - interactor.perform(MouseClick()) # activate edit mode - interactor.perform(KeySequence("abc")) + wrapper = tester.find_by_name(ui, "values").locate(Cell(5, 0)) + wrapper.perform(MouseClick()) # activate edit mode + wrapper.perform(KeySequence("abc")) self.assertEqual(object_list.selected.value, "abc") # second column refers to an Int type original = object_list.selected.other_value - interactor = tester.find_by_name(ui, "values").locate(Cell(5, 1)) - interactor.perform(MouseClick()) - interactor.perform(KeySequence("abc")) # invalid + wrapper = tester.find_by_name(ui, "values").locate(Cell(5, 1)) + wrapper.perform(MouseClick()) + wrapper.perform(KeySequence("abc")) # invalid self.assertEqual(object_list.selected.other_value, original) - interactor.perform(KeySequence("\b\b\b12")) # now ok + wrapper.perform(KeySequence("\b\b\b12")) # now ok self.assertEqual(object_list.selected.other_value, 12) @requires_toolkit([ToolkitName.qt, ToolkitName.wx]) @@ -552,14 +552,14 @@ def test_table_editor_check_display_with_tester(self): ) tester = UITester() with tester.create_ui(object_list, dict(view=select_row_view)) as ui: - interactor = tester.find_by_name(ui, "values").locate(Cell(0, 1)) + wrapper = tester.find_by_name(ui, "values").locate(Cell(0, 1)) - actual = interactor.inspect(DisplayedText()) + actual = wrapper.inspect(DisplayedText()) self.assertEqual(actual, "0") object_list.values[0].other_value = 123 - actual = interactor.inspect(DisplayedText()) + actual = wrapper.inspect(DisplayedText()) self.assertEqual(actual, "123") @requires_toolkit([ToolkitName.qt])