From e770e49ab0a75bd2dea7abcd5ce38e584e72155b Mon Sep 17 00:00:00 2001 From: Talv Date: Tue, 8 Sep 2015 05:35:42 +0200 Subject: [PATCH] Fixed and updated tests for X11. --- tests/test_unix.py | 60 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/tests/test_unix.py b/tests/test_unix.py index 758ecfd..00a60f7 100644 --- a/tests/test_unix.py +++ b/tests/test_unix.py @@ -6,7 +6,7 @@ on Ubuntu: sudo apt-get install python-nose - sudo apt-get install xvfb + sudo apt-get install xvfb sudo apt-get install xserver-xephyr sudo apt-get install python-setuptools sudo easy_install PyVirtualDisplay @@ -36,13 +36,21 @@ (0, 0), (10, 20), (-10, -20), - (5, 0), (2222, 2222), + (5, 0), (9, 19), ] +buttons = [1, 2, 3, 10] # 10 = mouse btn6 class Event(PyMouseEvent): + def reset(self): + self.pos = None + self.button = None + self.press = None + self.scroll_vertical = None + self.scroll_horizontal = None + def move(self, x, y): print("Mouse moved to", x, y) self.pos = (x, y) @@ -52,6 +60,12 @@ def click(self, x, y, button, press): print("Mouse pressed at", x, y, "with button", button) else: print("Mouse released at", x, y, "with button", button) + self.button = button + self.press = press + + def scroll(self, x, y, vertical, horizontal): + self.scroll_vertical = vertical + self.scroll_horizontal = horizontal def expect_pos(pos, size): def expect(x, m): @@ -79,14 +93,48 @@ def test_move(self): def test_event(self): for size in screen_sizes: with Display(visible=VISIBLE, size=size): - time.sleep(3) # TODO: how long should we wait? + time.sleep(1.0) # TODO: how long should we wait? mouse = PyMouse() event = Event() event.start() + # check move for p in positions: - event.pos = None + event.reset() mouse.move(*p) - time.sleep(0.1) # TODO: how long should we wait? + time.sleep(0.01) print('check ', expect_pos(p, size), '=', event.pos) eq_(expect_pos(p, size), event.pos) - event.stop() + # check buttons + for btn in buttons: + # press + event.reset() + mouse.press(0, 0, btn) + time.sleep(0.01) + print("check button", btn, "pressed") + eq_(btn, event.button) + eq_(True, event.press) + # release + event.reset() + mouse.release(0, 0, btn) + time.sleep(0.01) + print("check button", btn, "released") + eq_(btn, event.button) + eq_(False, event.press) + # check scroll + def check_scroll(btn, vertical=None, horizontal=None): + event.reset() + mouse.press(0, 0, btn) + time.sleep(0.01) + if vertical: + eq_(vertical, event.scroll_vertical) + elif horizontal: + eq_(horizontal, event.scroll_horizontal) + print("check scroll up") + check_scroll(4, 1, 0) + print("check scroll down") + check_scroll(5, -1, 0) + print("check scroll left") + check_scroll(6, 0, 1) + print("check scroll right") + check_scroll(7, 0, -1) + event.stop()