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

Allow sending "mouse move" with left/right down with EnableTestAssistant #715

Merged
merged 8 commits into from
Mar 15, 2021
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
27 changes: 23 additions & 4 deletions enable/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
# Thanks for using Enthought open source!
from unittest.mock import Mock

from traits.api import Undefined

from enable.abstract_window import AbstractWindow
from enable.events import DragEvent, KeyEvent, MouseEvent
from kiva.testing import KivaTestAssistant
Expand Down Expand Up @@ -89,6 +91,7 @@ def press_move_release(self, interactor, points, window=None,
alt_down=alt_down,
control_down=control_down,
shift_down=shift_down,
left_down=True,
)
x, y = points[-1]
self.mouse_up(
Expand Down Expand Up @@ -298,7 +301,8 @@ def mouse_dclick(self, interactor, x, y, button="left", window=None,
return event

def mouse_move(self, interactor, x, y, window=None, alt_down=False,
control_down=False, shift_down=False):
control_down=False, shift_down=False, left_down=Undefined,
middle_down=Undefined, right_down=Undefined):
""" Send a mouse move event to the interactor.

Parameters
Expand All @@ -320,16 +324,28 @@ def mouse_move(self, interactor, x, y, window=None, alt_down=False,
get_pointer_position() or should use a mock for the method.

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

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

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

left_down : boolean, optional
The mouse is moved while `left` is down. Default value is
Undefined.

middle_down : boolean, optional
The mouse is moved while `middle` is down. Default value is
Undefined.

right_down : boolean, optional
The mouse is moved while `right` is down. Default value is
Undefined.

Returns
-------
event : MouseEvent
Expand All @@ -343,6 +359,9 @@ def mouse_move(self, interactor, x, y, window=None, alt_down=False,
alt_down=alt_down,
control_down=control_down,
shift_down=shift_down,
left_down=left_down,
middle_down=middle_down,
right_down=right_down,
)
if hasattr(window.get_pointer_position, "return_value"):
# Note: Non-mock windows shouldn't try to get pointer position
Expand Down
9 changes: 9 additions & 0 deletions enable/tests/test_test_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ def test_mouse_down(self):
test_assistant.mouse_down(component, x=0, y=0)
component.normal_left_down.assert_called_once()

def test_mouse_move_while_down(self):
test_assistant = EnableTestAssistant()
component = Component(bounds=[100, 200])
event = test_assistant.mouse_move(component, 10, 20, left_down=True)

self.assertEqual(event.x, 10)
self.assertEqual(event.y, 20)
self.assertIs(event.left_down, True)

def test_mouse_dclick(self):
test_assistant = EnableTestAssistant()
component = Component(bounds=[100, 200])
Expand Down
12 changes: 6 additions & 6 deletions enable/tests/tools/pyface/test_move_command_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ def test_drag_component(self):

# start moving the mouse
mouse_move_event = self.mouse_move(
self.component, 145, 145, window=window
self.component, 145, 145, window=window, left_down=True
)
self.assertTrue(mouse_move_event.handled)

# move the mouse to the final location
mouse_move_event = self.mouse_move(
self.component, 195, 95, window=window
self.component, 195, 95, window=window, left_down=True
)
self.assertTrue(mouse_move_event.handled)

Expand Down Expand Up @@ -87,13 +87,13 @@ def test_drag_cancel(self):

# start moving the mouse
mouse_move_event = self.mouse_move(
self.component, 145, 145, window=window
self.component, 145, 145, window=window, left_down=True
)
self.assertTrue(mouse_move_event.handled)

# move the mouse to the final location
mouse_move_event = self.mouse_move(
self.component, 195, 95, window=window
self.component, 195, 95, window=window, left_down=True
)
self.assertTrue(mouse_move_event.handled)

Expand Down Expand Up @@ -121,13 +121,13 @@ def test_drag_resize_move_command(self):

# start moving the mouse
mouse_move_event = self.mouse_move(
self.component, 145, 145, window=window
self.component, 145, 145, window=window, left_down=True
)
self.assertTrue(mouse_move_event.handled)

# move the mouse to the final location
mouse_move_event = self.mouse_move(
self.component, 195, 95, window=window
self.component, 195, 95, window=window, left_down=True
)
self.assertTrue(mouse_move_event.handled)

Expand Down
8 changes: 4 additions & 4 deletions enable/tests/tools/pyface/test_resize_command_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ def test_drag_component(self):

# start moving the mouse
mouse_move_event = self.mouse_move(
self.component, 145, 145, window=window
self.component, 145, 145, window=window, left_down=True
)
self.assertTrue(mouse_move_event.handled)

# move the mouse to the final location
mouse_move_event = self.mouse_move(
self.component, 195, 95, window=window
self.component, 195, 95, window=window, left_down=True
)
self.assertTrue(mouse_move_event.handled)

Expand Down Expand Up @@ -87,13 +87,13 @@ def test_drag_cancel(self):

# start moving the mouse
mouse_move_event = self.mouse_move(
self.component, 145, 145, window=window
self.component, 145, 145, window=window, left_down=True
)
self.assertTrue(mouse_move_event.handled)

# move the mouse to the final location
mouse_move_event = self.mouse_move(
self.component, 195, 95, window=window
self.component, 195, 95, window=window, left_down=True
)
self.assertTrue(mouse_move_event.handled)

Expand Down