on xenial help sign in
Create class DragMixin and import it to share code for _drag function
commit6755c6453b40fb2129bd7c0db8e96cc3aa28eb11 authorAndrea Cimitan <andrea.cimitan@gmail.com> dateWed 2 Oct 2013, 10:24 (13 years ago) parentc872390
3 files changed+18−29
tests/autopilot/unity8/shell/__init__.py+14 tests/autopilot/unity8/shell/emulators/hud.py+2−14 tests/autopilot/unity8/shell/tests/test_hud.py+2−15
tests/autopilot/unity8/shell/__init__.py+14
@@ -19,6 +19,7 @@
1919
2020"""unity shell autopilot tests and emulators - sub level package."""
2121
22+from time import sleep
2223from functools import wraps
2324import logging
2425
@@ -46,3 +47,16 @@ def disable_qml_mocking(fn):
4647 tests_self._qml_mock_enabled = False
4748 return fn(*args, **kwargs)
4849 return wrapper
50+
51+class DragMixin(object):
52+ def _drag(self, x1, y1, x2, y2):
53+ cur_x = x1
54+ cur_y = y1
55+ dx = 1.0 * (x2 - x1) / 100
56+ dy = 1.0 * (y2 - y1) / 100
57+ for i in range(0, 100):
58+ self.touch._finger_move(int(cur_x), int(cur_y))
59+ sleep(0.002)
60+ cur_x += dx
61+ cur_y += dy
62+ self.touch._finger_move(int(x2), int(y2))
tests/autopilot/unity8/shell/emulators/hud.py+2−14
@@ -21,12 +21,12 @@ from collections import namedtuple
2121
2222from unity8 import get_grid_size
2323from unity8.shell.emulators import UnityEmulatorBase
24+from unity8.shell import DragMixin
2425from autopilot.input import Touch
25−from time import sleep
2626
2727SwipeCoords = namedtuple('SwipeCoords', 'start_x end_x start_y end_y')
2828
29−class Hud(UnityEmulatorBase):
29+class Hud(UnityEmulatorBase, DragMixin):
3030
3131 """An emulator that understands the Hud."""
3232
@@ -77,15 +77,3 @@ class Hud(UnityEmulatorBase):
7777 end_y = main_view.y + int(hud_show_button.y + (hud_show_button.height/2))
7878
7979 return SwipeCoords(start_x, end_x, start_y, end_y)
80−
81− def _drag(self, x1, y1, x2, y2):
82− cur_x = x1
83− cur_y = y1
84− dx = 1.0 * (x2 - x1) / 100
85− dy = 1.0 * (y2 - y1) / 100
86− for i in range(0, 100):
87− self.touch._finger_move(int(cur_x), int(cur_y))
88− sleep(0.002)
89− cur_x += dx
90− cur_y += dy
91− self.touch._finger_move(int(x2), int(y2))
tests/autopilot/unity8/shell/tests/test_hud.py+2−15
@@ -19,14 +19,13 @@
1919
2020from __future__ import absolute_import
2121
22−from unity8.shell import with_lightdm_mock
22+from unity8.shell import with_lightdm_mock, DragMixin
2323from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
2424
2525from testtools.matchers import Equals
2626from autopilot.matchers import Eventually
27−from time import sleep
2827
29−class TestHud(UnityTestCase):
28+class TestHud(UnityTestCase, DragMixin):
3029
3130 """Tests the Shell HUD."""
3231
@@ -189,15 +188,3 @@ class TestHud(UnityTestCase):
189188 """Only release the finger if it is in fact down."""
190189 if self.touch._touch_finger is not None:
191190 self.touch.release()
192−
193− def _drag(self, x1, y1, x2, y2):
194− cur_x = x1
195− cur_y = y1
196− dx = 1.0 * (x2 - x1) / 100
197− dy = 1.0 * (y2 - y1) / 100
198− for i in range(0, 100):
199− self.touch._finger_move(int(cur_x), int(cur_y))
200− sleep(0.002)
201− cur_x += dx
202− cur_y += dy
203− self.touch._finger_move(int(x2), int(y2))