Unity 8
 All Classes Functions Properties
__init__.py
1 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2 #
3 # Unity Autopilot Test Suite
4 # Copyright (C) 2012-2013 Canonical
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #
19 
20 """unity shell autopilot tests and emulators - sub level package."""
21 
22 from time import sleep
23 from functools import wraps
24 import logging
25 
26 
27 logger = logging.getLogger(__name__)
28 
29 
30 def with_lightdm_mock(mock_type):
31  """A simple decorator that sets up the LightDM mock for a single test."""
32  def with_lightdm_mock_internal(fn):
33  @wraps(fn)
34  def wrapper(*args, **kwargs):
35  tests_self = args[0]
36  tests_self.patch_lightdm_mock(mock_type)
37  return fn(*args, **kwargs)
38  return wrapper
39  return with_lightdm_mock_internal
40 
41 
42 def disable_qml_mocking(fn):
43  """Simple decorator that disables the QML mocks from being loaded."""
44  @wraps(fn)
45  def wrapper(*args, **kwargs):
46  tests_self = args[0]
47  tests_self._qml_mock_enabled = False
48  return fn(*args, **kwargs)
49  return wrapper
50 
51 class DragMixin(object):
52  def _drag(self, x1, y1, x2, y2):
53  # XXX This ugly code is here just temporarily, waiting for drag
54  # improvements to land on autopilot so we don't have to access device
55  # private internal attributes. --elopio - 2014-02-12
56  cur_x = x1
57  cur_y = y1
58  dx = 1.0 * (x2 - x1) / 100
59  dy = 1.0 * (y2 - y1) / 100
60  for i in range(0, 100):
61  try:
62  self.touch._finger_move(int(cur_x), int(cur_y))
63  except AttributeError:
64  self.touch._device.finger_move(int(cur_x), int(cur_y))
65  sleep(0.002)
66  cur_x += dx
67  cur_y += dy
68  try:
69  self.touch._finger_move(int(x2), int(y2))
70  except AttributeError:
71  self.touch._device.finger_move(int(x2), int(y2))