on xenial help sign in
Create class DragMixin and import it to share code for _drag function
6755c64Andrea Cimitan
tests/autopilot/unity8/shell/__init__.py+14
@@ -19,6 +19,7 @@
19
19
20"""unity shell autopilot tests and emulators - sub level package."""
20"""unity shell autopilot tests and emulators - sub level package."""
21
21
22+from time import sleep
22from functools import wraps
23from functools import wraps
23import logging
24import logging
24
25
@@ -46,3 +47,16 @@ def disable_qml_mocking(fn):
46 tests_self._qml_mock_enabled = False
47 tests_self._qml_mock_enabled = False
47 return fn(*args, **kwargs)
48 return fn(*args, **kwargs)
48 return wrapper
49 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
21
21
22from unity8 import get_grid_size
22from unity8 import get_grid_size
23from unity8.shell.emulators import UnityEmulatorBase
23from unity8.shell.emulators import UnityEmulatorBase
24+from unity8.shell import DragMixin
24from autopilot.input import Touch
25from autopilot.input import Touch
25−from time import sleep
26
26
27SwipeCoords = namedtuple('SwipeCoords', 'start_x end_x start_y end_y')
27SwipeCoords = namedtuple('SwipeCoords', 'start_x end_x start_y end_y')
28
28
29−class Hud(UnityEmulatorBase):
29+class Hud(UnityEmulatorBase, DragMixin):
30
30
31 """An emulator that understands the Hud."""
31 """An emulator that understands the Hud."""
32
32
@@ -77,15 +77,3 @@ class Hud(UnityEmulatorBase):
77 end_y = main_view.y + int(hud_show_button.y + (hud_show_button.height/2))
77 end_y = main_view.y + int(hud_show_button.y + (hud_show_button.height/2))
78
78
79 return SwipeCoords(start_x, end_x, start_y, end_y)
79 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 @@
19
19
20from __future__ import absolute_import
20from __future__ import absolute_import
21
21
22−from unity8.shell import with_lightdm_mock
22+from unity8.shell import with_lightdm_mock, DragMixin
23from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
23from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
24
24
25from testtools.matchers import Equals
25from testtools.matchers import Equals
26from autopilot.matchers import Eventually
26from autopilot.matchers import Eventually
27−from time import sleep
28
27
29−class TestHud(UnityTestCase):
28+class TestHud(UnityTestCase, DragMixin):
30
29
31 """Tests the Shell HUD."""
30 """Tests the Shell HUD."""
32
31
@@ -189,15 +188,3 @@ class TestHud(UnityTestCase):
189 """Only release the finger if it is in fact down."""
188 """Only release the finger if it is in fact down."""
190 if self.touch._touch_finger is not None:
189 if self.touch._touch_finger is not None:
191 self.touch.release()
190 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))