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

[WIP] MultitouchSimulatorTestCase: Fix CI failing test #7476

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6fadb40
Fix MultitouchSimulatorTestCase which fails on CI.
pythonic64 Apr 9, 2021
0bc3403
Fix MultitouchSimulatorTestCase.multitouch_dot_touch which fails on CI.
pythonic64 Apr 9, 2021
1981f32
Fix MultitouchSimulatorTestCase.multitouch_dot_move which fails on CI.
pythonic64 Apr 11, 2021
d861d5d
Print touch events in multitouch_dot_move method.
pythonic64 Apr 20, 2021
15186f7
Print touch events in multitouch_dot_touch method.
pythonic64 Apr 20, 2021
39f7ac1
Clearing event references from EventLoop and postprocessors.
pythonic64 Apr 20, 2021
33fc714
Remove dispatch of on_mouch_move events from MultitouchSimulatorTestC…
pythonic64 Apr 20, 2021
81c866c
Set Window.rotation to 0 in MultitouchSimulatorTestCase.
pythonic64 Apr 20, 2021
39a8e2d
Disabled hover event in MultitouchSimulatorTestCase.
pythonic64 Apr 21, 2021
e0dab4b
Restore patching of Window.on_close with on_window_close method.
pythonic64 Apr 21, 2021
0ff3689
Dispatching 'on_cursor_leave' to cleanup hover event.
pythonic64 Apr 23, 2021
f16d89b
Added method clear_event_loop_and_window to GraphicUnitTest.
pythonic64 Apr 23, 2021
48f4400
Enabled hover events in MultitouchSimulatorTestCase.
pythonic64 Apr 23, 2021
ad9750a
Disabled hover event in MultitouchSimulatorTestCase.
pythonic64 Apr 23, 2021
87906f1
Better cleanup in MultitouchSimulatorTestCase.
pythonic64 Apr 23, 2021
35e5bb6
Cleanup touch event from scatter instance in MultitouchSimulatorTestC…
pythonic64 Apr 24, 2021
060bd34
MultitouchSimulatorTestCase: Always assert that events are cleared.
pythonic64 Apr 24, 2021
1613a4d
MouseHoverEventTestCase: Set framecount to 2.
pythonic64 Apr 24, 2021
ca85721
MultitouchSimulatorTestCase: Removed unused ellipse variable.
pythonic64 Apr 24, 2021
1030dd1
Disable on_window_flip method in MouseHoverEventTestCase.
pythonic64 Apr 24, 2021
b7b6135
MultitouchSimulatorTestCase: Set framecount attribute to 2.
pythonic64 Apr 27, 2021
abe6fae
Added attribute _running in MouseMotionEventProvider and commented-ou…
pythonic64 Apr 27, 2021
3a643d8
MultitouchSimulatorTestCase: Don't render widgets and set framecount …
pythonic64 Apr 27, 2021
54efe99
Merge branch 'master' into bugfix-attempt_to_fix_test_mouse_hover_eve…
pythonic64 May 2, 2021
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
36 changes: 22 additions & 14 deletions kivy/input/providers/mouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ def __init__(self, device, args):
self.disable_on_activity = False
self.disable_multitouch = False
self.multitouch_on_demand = False
self.hover_disabled = False
self.hover_event = None
self._running = False
# split arguments
args = args.split(',')
for arg in args:
Expand All @@ -161,38 +163,44 @@ def __init__(self, device, args):
self.disable_multitouch = True
elif arg == 'multitouch_on_demand':
self.multitouch_on_demand = True
elif arg == 'hover_disabled':
self.hover_disabled = True
else:
Logger.error('Mouse: unknown parameter <%s>' % arg)

def start(self):
'''Start the mouse provider'''
if not EventLoop.window:
if not EventLoop.window or self._running:
return
self._running = True
fbind = EventLoop.window.fbind
fbind('on_mouse_down', self.on_mouse_press)
fbind('on_mouse_move', self.on_mouse_motion)
fbind('on_mouse_up', self.on_mouse_release)
fbind('mouse_pos', self.begin_or_update_hover_event)
fbind('system_size', self.update_hover_event)
fbind('on_cursor_enter', self.begin_hover_event)
fbind('on_cursor_leave', self.end_hover_event)
fbind('on_close', self.end_hover_event)
fbind('on_rotate', self.update_hover_event)
if not self.hover_disabled:
fbind('mouse_pos', self.begin_or_update_hover_event)
fbind('system_size', self.update_hover_event)
fbind('on_cursor_enter', self.begin_hover_event)
fbind('on_cursor_leave', self.end_hover_event)
fbind('on_close', self.end_hover_event)
fbind('on_rotate', self.update_hover_event)

def stop(self):
'''Stop the mouse provider'''
if not EventLoop.window:
if not EventLoop.window or not self._running:
return
self._running = False
funbind = EventLoop.window.funbind
funbind('on_mouse_down', self.on_mouse_press)
funbind('on_mouse_move', self.on_mouse_motion)
funbind('on_mouse_up', self.on_mouse_release)
funbind('mouse_pos', self.begin_or_update_hover_event)
funbind('system_size', self.update_hover_event)
funbind('on_cursor_enter', self.begin_hover_event)
funbind('on_cursor_leave', self.end_hover_event)
funbind('on_close', self.end_hover_event)
funbind('on_rotate', self.update_hover_event)
if not self.hover_disabled:
funbind('mouse_pos', self.begin_or_update_hover_event)
funbind('system_size', self.update_hover_event)
funbind('on_cursor_enter', self.begin_hover_event)
funbind('on_cursor_leave', self.end_hover_event)
funbind('on_close', self.end_hover_event)
funbind('on_rotate', self.update_hover_event)

def test_activity(self):
if not self.disable_on_activity:
Expand Down
16 changes: 14 additions & 2 deletions kivy/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ def setUp(self):
Window.initialized = True
Window.canvas.clear()
Window.close = lambda *s: True
self.clear_event_loop_and_window()

def clear_event_loop_and_window(self):
from kivy.base import EventLoop
for child in self.Window.children[:]:
self.Window.remove_widget(child)
EventLoop.touches.clear()
for post_proc in EventLoop.postproc_modules:
if hasattr(post_proc, 'touches'):
post_proc.touches.clear()
elif hasattr(post_proc, 'last_touches'):
post_proc.last_touches.clear()

def on_window_flip(self, window):
'''Internal method to be called when the window have just displayed an
Expand Down Expand Up @@ -299,10 +311,10 @@ def tearDown(self, fake=False):
'''
from kivy.base import stopTouchApp
from kivy.core.window import Window
from kivy.clock import Clock
Window.unbind(on_flip=self.on_window_flip)
self.clear_event_loop_and_window()
self.Window = None
stopTouchApp()

if not fake and self.test_failed:
self.assertTrue(False)
super(GraphicUnitTest, self).tearDown()
Expand Down
5 changes: 4 additions & 1 deletion kivy/tests/test_mouse_hover_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def setUp(self):
# window from event listeners list.
if not (platform == 'win' and 'CI' in os.environ):
self.old_on_close = win.on_close
win.on_close = lambda *args: None
win.on_close = self.on_window_close

def tearDown(self, fake=False):
self.etype = None
Expand Down Expand Up @@ -60,6 +60,9 @@ def tearDown(self, fake=False):
self.old_on_close = None
super().tearDown(fake)

def on_window_close(self, *args, **kwargs):
pass

def on_window_flip(self, window):
# Not rendering widgets in tests so don't do screenshots
pass
Expand Down
81 changes: 65 additions & 16 deletions kivy/tests/test_mouse_multitouchsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def mouse_init(self, on_demand=False, disabled=False, scatter=False):
mode = 'disable_multitouch'
else:
mode = ''
mode = mode + ',hover_disabled'
from kivy.input.providers.mouse import MouseMotionEventProvider
mouse = MouseMotionEventProvider('unittest', mode)
mouse.is_touch = True
Expand All @@ -47,6 +48,10 @@ def mouse_init(self, on_demand=False, disabled=False, scatter=False):
self.assertTrue(mouse.multitouch_on_demand)
return (eventloop, win, mouse, wid)

def remove_sim_touch(self, win, x, y):
win.dispatch('on_mouse_down', x, self.correct_y(win, y), 'left', {})
win.dispatch('on_mouse_up', x, self.correct_y(win, y), 'left', {})

def multitouch_dot_touch(self, button, **kwargs):
# touch -> dot appears -> touch again -> dot disappears
eventloop, win, mouse, wid = self.mouse_init(**kwargs)
Expand All @@ -70,10 +75,14 @@ def multitouch_dot_touch(self, button, **kwargs):

if 'on_demand' in kwargs and 'scatter' not in kwargs:
# doesn't do anything on a pure Button
self.render(wid)

# self.render(wid)
# cleanup!
# remove mouse provider
win.dispatch(
'on_mouse_up',
10, self.correct_y(win, 10),
'right', {}
)
self.assertFalse(mouse.touches)
mouse.stop()
eventloop.remove_input_provider(mouse)
return
Expand All @@ -94,7 +103,9 @@ def multitouch_dot_touch(self, button, **kwargs):
# called == multitouch_sim is False
self.advance_frames(1) # initialize stuff
wid.on_touch_down(mouse.touches[event_id])
mouse.touches[event_id].grab_state = True
wid.on_touch_up(mouse.touches[event_id])
mouse.touches[event_id].grab_state = False
self.assertTrue(mouse.touches[event_id].multitouch_sim)

elif 'disabled' in kwargs:
Expand Down Expand Up @@ -124,6 +135,10 @@ def multitouch_dot_touch(self, button, **kwargs):
# because the red dot is removed by the left button
if 'disabled' not in kwargs:
self.assertIn(event_id, mouse.touches)
print(mouse.touches)
print('Mouse touches count: %s' % len(mouse.touches))
print('Hover event: %s' % mouse.hover_event)
print('Eventloop.me_list count: %s' % len(eventloop.me_list))
self.assertIsNotNone(
mouse.touches[event_id].ud.get('_drawelement')
) # the red dot is present
Expand All @@ -146,7 +161,12 @@ def multitouch_dot_touch(self, button, **kwargs):
event_id, mouse.touches
)
# cleanup!
# remove mouse provider
win.dispatch(
'on_mouse_up',
10, self.correct_y(win, 10),
button, {}
)
self.assertFalse(mouse.touches)
mouse.stop()
eventloop.remove_input_provider(mouse)
return
Expand Down Expand Up @@ -191,7 +211,12 @@ def multitouch_dot_touch(self, button, **kwargs):
mouse.touches[event_id].ud.get('_drawelement')
) # the red dot is present

self.render(wid)
# self.render(wid)

# remove red dot
if button == 'right':
self.remove_sim_touch(win, 10, 10)
self.assertFalse(mouse.touches)

# cleanup!
# remove mouse provider
Expand Down Expand Up @@ -223,10 +248,14 @@ def multitouch_dot_move(self, button, **kwargs):

if 'on_demand' in kwargs and 'scatter' not in kwargs:
# doesn't do anything on a pure Button
self.render(wid)

# self.render(wid)
# cleanup!
# remove mouse provider
win.dispatch(
'on_mouse_up',
10, self.correct_y(win, 10),
'right', {}
)
self.assertFalse(mouse.touches)
mouse.stop()
eventloop.remove_input_provider(mouse)
return
Expand Down Expand Up @@ -254,17 +283,22 @@ def multitouch_dot_move(self, button, **kwargs):
# called == multitouch_sim is False
self.advance_frames(1) # initialize stuff
wid.on_touch_down(mouse.touches[event_id])
mouse.touches[event_id].grab_state = True
wid.on_touch_up(mouse.touches[event_id])
mouse.touches[event_id].grab_state = False
self.assertTrue(mouse.touches[event_id].multitouch_sim)

win.dispatch(
'on_mouse_up',
10, self.correct_y(win, 10),
'right', {}
)
ellipse = mouse.touches[
event_id
].ud.get('_drawelement')[1].proxy_ref
print(mouse.touches)
print('Mouse touches count: %s' % len(mouse.touches))
print('Hover event: %s' % mouse.hover_event)
print('Eventloop.me_list count: %s' % len(eventloop.me_list))
self.assertIsNotNone(
mouse.touches[event_id].ud.get('_drawelement')
)
win.dispatch(
'on_mouse_down',
10, self.correct_y(win, 10),
Expand All @@ -289,7 +323,12 @@ def multitouch_dot_move(self, button, **kwargs):
mouse.touches[event_id].ud.get('_drawelement')
) # the red dot isn't present
# cleanup!
# remove mouse provider
win.dispatch(
'on_mouse_up',
10, self.correct_y(win, 10),
'right', {}
)
self.assertFalse(mouse.touches)
mouse.stop()
eventloop.remove_input_provider(mouse)
return
Expand Down Expand Up @@ -368,7 +407,11 @@ def multitouch_dot_move(self, button, **kwargs):
mouse.touches[event_id].ud.get('_drawelement')
) # the red dot is present

self.render(wid)
# self.render(wid)

if button == 'right':
self.remove_sim_touch(win, 50, 50)
self.assertFalse(mouse.touches)

# cleanup!
# remove mouse provider
Expand Down Expand Up @@ -416,7 +459,9 @@ def test_multitouch_dontappear(self):
self.assertNotIn(event_id, mouse.touches)

self.advance_frames(1)
self.render(wid)
# self.render(wid)

self.assertFalse(mouse.touches)

# cleanup!
# remove mouse provider
Expand Down Expand Up @@ -485,7 +530,11 @@ def test_multitouch_appear(self):
mouse.touches[event_id].ud.get('_drawelement')
) # the red dot is present

self.render(wid)
self.advance_frames(1)
# self.render(wid)

self.remove_sim_touch(win, 11, 11)
self.assertFalse(mouse.touches)

# cleanup!
# remove mouse provider
Expand Down