Skip to content

Commit

Permalink
GraphicUnitTest: Added clear_window_and_event_loop method.
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonic64 committed May 4, 2021
1 parent c2b75c5 commit a3a48b8
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions kivy/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,23 @@ def setUp(self):
Window.create_window()
Window.register()
Window.initialized = True
Window.canvas.clear()
Window.close = lambda *s: True
Window.close = lambda *s: None
self.clear_window_and_event_loop()

def clear_window_and_event_loop(self):
from kivy.base import EventLoop
window = self.Window
for child in window.children[:]:
window.remove_widget(child)
window.canvas.before.clear()
window.canvas.clear()
window.canvas.after.clear()
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 +314,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_window_and_event_loop()
self.Window = None
stopTouchApp()

if not fake and self.test_failed:
self.assertTrue(False)
super(GraphicUnitTest, self).tearDown()
Expand Down

0 comments on commit a3a48b8

Please sign in to comment.