Skip to content

Commit

Permalink
Fixed and updated tests for X11.
Browse files Browse the repository at this point in the history
  • Loading branch information
Talv committed Sep 8, 2015
1 parent 6c7ba1b commit e770e49
Showing 1 changed file with 54 additions and 6 deletions.
60 changes: 54 additions & 6 deletions tests/test_unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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()

0 comments on commit e770e49

Please sign in to comment.