20 """unity shell autopilot tests and emulators - sub level package."""
22 from time
import sleep
23 from functools
import wraps
24 from gi.repository
import Notify
28 logger = logging.getLogger(__name__)
31 def with_lightdm_mock(mock_type):
32 """A simple decorator that sets up the LightDM mock for a single test."""
33 def with_lightdm_mock_internal(fn):
35 def wrapper(*args, **kwargs):
37 tests_self.patch_lightdm_mock(mock_type)
38 return fn(*args, **kwargs)
40 return with_lightdm_mock_internal
43 def disable_qml_mocking(fn):
44 """Simple decorator that disables the QML mocks from being loaded."""
46 def wrapper(*args, **kwargs):
48 tests_self._qml_mock_enabled =
False
49 return fn(*args, **kwargs)
53 class DragMixin(object):
54 def _drag(self, x1, y1, x2, y2):
60 dx = 1.0 * (x2 - x1) / 100
61 dy = 1.0 * (y2 - y1) / 100
62 for i
in range(0, 100):
64 self.touch._finger_move(int(cur_x), int(cur_y))
65 except AttributeError:
66 self.touch._device.finger_move(int(cur_x), int(cur_y))
71 self.touch._finger_move(int(x2), int(y2))
72 except AttributeError:
73 self.touch._device.finger_move(int(x2), int(y2))
76 def create_ephemeral_notification(
83 """Create an ephemeral (non-interactive) notification
85 :param summary: Summary text for the notification
86 :param body: Body text to display in the notification
87 :param icon: Path string to the icon to use
88 :param hint_strings: List of tuples containing the 'name' and value
89 for setting the hint strings for the notification
90 :param urgency: Urgency string for the noticiation, either: 'LOW',
96 "Creating ephemeral: summary(%s), body(%s), urgency(%r) "
104 notification = Notify.Notification.new(summary, body, icon)
108 notification.set_hint_string(key, value)
109 logger.info(
"Adding hint to notification: (%s, %s)", key, value)
110 notification.set_urgency(_get_urgency(urgency))
115 def _get_urgency(urgency):
116 """Translates urgency string to enum."""
117 _urgency_enums = {
'LOW': Notify.Urgency.LOW,
118 'NORMAL': Notify.Urgency.NORMAL,
119 'CRITICAL': Notify.Urgency.CRITICAL}
120 return _urgency_enums.get(urgency.upper())