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

Add dclick option to test assistant #444

Merged
merged 3 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions enable/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,58 @@ def mouse_down(self, interactor, x, y, button='left', window=None,
'{0}_down'.format(button))
return event

def mouse_dclick(self, interactor, x, y, button='left', window=None,
alt_down=False, control_down=False, shift_down=False):
""" Send a mouse double-click event to the interactor.

Parameters
----------
interactor : Interactor
The interactor (or subclass) where to dispatch the event.

x : float
The x coordinates of the mouse position

y : float
The y coordinates of the mouse position

button : {'left', 'right'}, optional
The mouse button for which to simulate a press (down) action.

window : AbstractWindow, optional
The enable AbstractWindow to associate with the event. Default
is to create a mock class instance. If the window has a mouse
owner then that interactor is used.

alt_down : boolean, optional
The button is pressed while `alt` is down. Default value is False.

control_down : boolean, optional
The button is pressed while `control` is down. Default value is
False.

shift_down : boolean, optional
The button is pressed while `shift` is down. Default value is
False.

Returns
-------
event : MouseEvent
The event instance after it has be processed by the `interactor`.

"""
window = self.create_mock_window() if window is None else window
event_attributes = {'x': x, 'y': y,
'alt_down': alt_down,
'control_down': control_down,
'shift_down': shift_down,
'{0}_down'.format(button): True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a while to understand if this "left_down" or "right_down" was necessary... I think it could potentially be handled by the window to change focus, so it makes sense to keep.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether or not it necessary, what matters is whether the generated event has the same features of the events which are generated by the backends, eg.

left_down=bool(buttons & QtCore.Qt.LeftButton),
middle_down=bool(buttons & QtCore.Qt.MidButton),
right_down=bool(buttons & QtCore.Qt.RightButton),

This doesn't allow generation of chorded double-click events, but that's probably for the best 😄

'window': window}
event = self.create_mouse_event(**event_attributes)
self._mouse_event_dispatch(interactor, event,
'{0}_dclick'.format(button))
return event

def mouse_move(self, interactor, x, y, window=None,
alt_down=False, control_down=False, shift_down=False):
""" Send a mouse move event to the interactor.
Expand Down
27 changes: 23 additions & 4 deletions enable/tests/test_assistant_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
except ImportError:
import mock
import nose
from unittest import skipIf

from traitsui.tests._tools import skip_if_null
from traits.etsconfig.api import ETSConfig

from enable.component import Component
from enable.testing import EnableTestAssistant, _MockWindow
Expand All @@ -23,7 +24,24 @@ def test_mouse_move():
assert not event.shift_down
nose.tools.assert_equal(event.window.get_pointer_position(), (10, 20))

@skip_if_null

def test_mouse_down():
test_assistant = EnableTestAssistant()
component = Component(bounds=[100, 200])
component.normal_left_down = mock.Mock()
test_assistant.mouse_down(component, x=0, y=0)
component.normal_left_down.assert_called_once()


def test_mouse_dclick():
test_assistant = EnableTestAssistant()
component = Component(bounds=[100, 200])
component.normal_left_dclick = mock.Mock()
test_assistant.mouse_dclick(component, x=0, y=0)
component.normal_left_dclick.assert_called_once()


@skipIf(ETSConfig.toolkit == "null", "Skipping null tookit")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not happy about this change.

def test_mouse_move_real_window():
from enable.api import Window

Expand All @@ -42,15 +60,16 @@ def test_mouse_move_real_window():
# can't test pointer position, not set, but if we get here it didn't
# try to set the pointer position

@skip_if_null

@skipIf(ETSConfig.toolkit == "null", "Skipping null tookit")
def test_mouse_move_real_window_mocked_position():
from enable.api import Window

test_assistant = EnableTestAssistant()
component = Component(bounds=[100, 200])

with mock.patch.object(Window, 'get_pointer_position',
return_value=None):
return_value=None):
window = Window(None, component=component)
event = test_assistant.mouse_move(component, 10, 20, window)

Expand Down