on xenial help sign in
Initial clean up of the autopilot tests set up.
2596125Leo Arias
tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+1−1
@@ -47,7 +47,7 @@ class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
47 end_y = start_y
47 end_y = start_y
48
48
49 logger.info("Swiping screen from the right edge")
49 logger.info("Swiping screen from the right edge")
50− self.touch.drag(start_x, start_y, end_x, end_y)
50+ self.main_window.pointing_device.drag(start_x, start_y, end_x, end_y)
51
51
52 def launch_fake_app(self):
52 def launch_fake_app(self):
53 _, desktop_file_path = self.create_test_application()
53 _, desktop_file_path = self.create_test_application()
tests/autopilot/unity8/fixture_setup.py+67−1
@@ -18,8 +18,9 @@
18#
18#
19
19
20import fixtures
20import fixtures
21−import subprocess
22import logging
21import logging
22+import os
23+import subprocess
23
24
24from autopilot import introspection
25from autopilot import introspection
25
26
@@ -29,9 +30,74 @@ from unity8 import (
29)
30)
30from unity8.shell import emulators
31from unity8.shell import emulators
31
32
33+
32logger = logging.getLogger(__name__)
34logger = logging.getLogger(__name__)
33
35
34
36
37+class RestartUnityWithTestability(fixtures.Fixture):
38+
39+ """Fixture to launch Unity8 with testability.
40+
41+ :ivar unity_proxy: The Autopilot proxy object for the Unity shell.
42+
43+ """
44+
45+ unity_proxy = None
46+
47+ def __init__(self, binary_path, variables):
48+ """Initialize the fixture instance.
49+
50+ :param str binary_path: The path to the Dash app binary.
51+ :param cli_arguments: The arguments to pass when launching the
52+ :param variables: The variables to use when launching the app.
53+ :type variables: A dictionary.
54+
55+ """
56+ super().__init__()
57+ self.binary_path = binary_path
58+ self.variables = variables
59+
60+ def setUp(self):
61+ """Restart unity with testability when the fixture is used."""
62+ super().setUp()
63+ self.addCleanup(self.stop_unity)
64+ self.restart_unity()
65+
66+ def restart_unity(self):
67+ self.restart_unity_with_testability()
68+
69+ def restart_unity_with_testability(self):
70+ self._unlink_mir_socket()
71+
72+ binary_arg = 'BINARY={}'.format(self.binary_path)
73+ variable_args = [
74+ '{}={}'.format(key, value) for key, value in self.variables.items()
75+ ]
76+ all_args = [binary_arg] + variable_args
77+
78+ self.unity_proxy = process_helpers.restart_unity_with_testability(
79+ *all_args)
80+
81+ def _unlink_mir_socket(self):
82+ # FIXME: we shouldn't be doing this
83+ # $MIR_SOCKET, fallback to $XDG_RUNTIME_DIR/mir_socket and
84+ # /tmp/mir_socket as last resort
85+ try:
86+ os.unlink(
87+ os.getenv('MIR_SOCKET',
88+ os.path.join(os.getenv('XDG_RUNTIME_DIR', "/tmp"),
89+ "mir_socket")))
90+ except OSError:
91+ pass
92+ try:
93+ os.unlink("/tmp/mir_socket")
94+ except OSError:
95+ pass
96+
97+ def stop_unity(self):
98+ process_helpers.stop_job('unity8')
99+
100+
35class LaunchDashApp(fixtures.Fixture):
101class LaunchDashApp(fixtures.Fixture):
36
102
37 """Fixture to launch the Dash app."""
103 """Fixture to launch the Dash app."""
tests/autopilot/unity8/indicators/tests/__init__.py−2
@@ -40,5 +40,3 @@ class DeviceIndicatorTestCase(IndicatorTestCase):
40 if platform.model() == 'Desktop':
40 if platform.model() == 'Desktop':
41 self.skipTest('Test cannot be run on the desktop.')
41 self.skipTest('Test cannot be run on the desktop.')
42 super().setUp()
42 super().setUp()
43− self.unity_proxy = self.launch_unity()
44− process_helpers.unlock_unity(self.unity_proxy)
tests/autopilot/unity8/shell/__init__.py−24
@@ -19,7 +19,6 @@
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
23from functools import wraps
22from functools import wraps
24from gi.repository import Notify
23from gi.repository import Notify
25
24
@@ -38,29 +37,6 @@ def disable_qml_mocking(fn):
38 return wrapper
37 return wrapper
39
38
40
39
41−class DragMixin():
42− def _drag(self, x1, y1, x2, y2):
43− # XXX This ugly code is here just temporarily, waiting for drag
44− # improvements to land on autopilot so we don't have to access device
45− # private internal attributes. --elopio - 2014-02-12
46− cur_x = x1
47− cur_y = y1
48− dx = 1.0 * (x2 - x1) / 100
49− dy = 1.0 * (y2 - y1) / 100
50− for i in range(0, 100):
51− try:
52− self.touch._finger_move(int(cur_x), int(cur_y))
53− except AttributeError:
54− self.touch._device.finger_move(int(cur_x), int(cur_y))
55− sleep(0.002)
56− cur_x += dx
57− cur_y += dy
58− try:
59− self.touch._finger_move(int(x2), int(y2))
60− except AttributeError:
61− self.touch._device.finger_move(int(x2), int(y2))
62−
63−
64def create_ephemeral_notification(
40def create_ephemeral_notification(
65 summary='',
41 summary='',
66 body='',
42 body='',
tests/autopilot/unity8/shell/tests/__init__.py+29−109
@@ -24,16 +24,14 @@ try:
24except ImportError:
24except ImportError:
25 Gio = None
25 Gio = None
26
26
27+import logging
28+import os
29+
27from autopilot import introspection
30from autopilot import introspection
28from autopilot.platform import model
31from autopilot.platform import model
29from autopilot.testcase import AutopilotTestCase
32from autopilot.testcase import AutopilotTestCase
30from autopilot.matchers import Eventually
33from autopilot.matchers import Eventually
31−from autopilot.input import Touch
32from autopilot.display import Display
34from autopilot.display import Display
33−import logging
34−import os.path
35−import subprocess
36−import sys
37from testtools.matchers import Equals
35from testtools.matchers import Equals
38from ubuntuuitoolkit import (
36from ubuntuuitoolkit import (
39 fixture_setup as toolkit_fixtures,
37 fixture_setup as toolkit_fixtures,
@@ -93,36 +91,25 @@ class UnityTestCase(AutopilotTestCase):
93 @classmethod
91 @classmethod
94 def setUpClass(cls):
92 def setUpClass(cls):
95 try:
93 try:
96− output = subprocess.check_output(
94+ is_unity_running = process_helpers.is_job_running('unity8')
97− ["/sbin/initctl", "status", "unity8"],
95+ except process_helpers.JobError as e:
98− stderr=subprocess.STDOUT,
96+ xdg_config_home = os.getenv(
99− universal_newlines=True,
97+ 'XDG_CONFIG_HOME', os.path.join(os.getenv('HOME'), '.config'))
100− )
98+ upstart_config_path = os.path.join(xdg_config_home, 'upstart')
101− except subprocess.CalledProcessError as e:
99+ logger.error(
102− sys.stderr.write(
103− "Error: `initctl status unity8` failed, most probably the "
100+ '`initctl status unity8` failed, most probably the '
104− "unity8 session could not be found:\n\n"
101+ 'unity8 session could not be found:\n\n'
105− "{0}\n"
102+ '{0}\n'
106− "Please install unity8 or copy data/unity8.conf to "
103+ 'Please install unity8 or copy data/unity8.conf to '
107− "{1}\n".format(
104+ '{1}\n'.format(e.output, upstart_config_path)
108− e.output,
109− os.path.join(os.getenv("XDG_CONFIG_HOME",
110− os.path.join(os.getenv("HOME"),
111− ".config")
112− ),
113− "upstart")
114− )
115− )
116− sys.exit(1)
117−
118− if "start/" in output:
119− sys.stderr.write(
120− "Error: Unity is currently running, these tests require it to "
121− "be 'stopped'.\n"
122− "Please run this command before running these tests: \n"
123− "initctl stop unity8\n"
124 )
105 )
125− sys.exit(2)
106+ raise e
107+ else:
108+ assert not is_unity_running, (
109+ 'Unity is currently running, these tests require it to be '
110+ 'stopped.\n'
111+ 'Please run this command before running these tests: \n'
112+ 'initctl stop unity8\n')
126
113
127 def setUp(self):
114 def setUp(self):
128 super().setUp()
115 super().setUp()
@@ -134,13 +121,6 @@ class UnityTestCase(AutopilotTestCase):
134 self._data_dirs_mock_enabled = True
121 self._data_dirs_mock_enabled = True
135 self._environment = {}
122 self._environment = {}
136
123
137− # FIXME: This is a work around re: lp:1238417
138− if model() != "Desktop":
139− from autopilot.input import _uinput
140− _uinput._touch_device = _uinput.create_touch_device()
141− self.addCleanup(_uinput._touch_device.close)
142−
143− self.touch = Touch.create()
144 self._setup_display_details()
124 self._setup_display_details()
145
125
146 def _setup_display_details(self):
126 def _setup_display_details(self):
@@ -196,40 +176,6 @@ class UnityTestCase(AutopilotTestCase):
196 divisor = divisor * 2
176 divisor = divisor * 2
197 return divisor
177 return divisor
198
178
199− def _patch_environment(self, key, value):
200− """Wrapper for patching env for upstart environment."""
201− try:
202− current_value = subprocess.check_output(
203− ["/sbin/initctl", "get-env", "--global", key],
204− stderr=subprocess.STDOUT,
205− universal_newlines=True,
206− ).rstrip()
207− except subprocess.CalledProcessError:
208− current_value = None
209−
210− subprocess.call([
211− "/sbin/initctl",
212− "set-env",
213− "--global",
214− "%s=%s" % (key, value)
215− ], stderr=subprocess.STDOUT)
216− self.addCleanup(self._upstart_reset_env, key, current_value)
217−
218− def _upstart_reset_env(self, key, value):
219− logger.info("Resetting upstart env %s to %s", key, value)
220− if value is None:
221− subprocess.call(
222− ["/sbin/initctl", "unset-env", key],
223− stderr=subprocess.STDOUT,
224− )
225− else:
226− subprocess.call([
227− "/sbin/initctl",
228− "set-env",
229− "--global",
230− "%s=%s" % (key, value)
231− ], stderr=subprocess.STDOUT)
232−
233 def launch_unity(self, mode="full-greeter", *args):
179 def launch_unity(self, mode="full-greeter", *args):
234 """
180 """
235 Launch the unity shell, return a proxy object for it.
181 Launch the unity shell, return a proxy object for it.
@@ -257,21 +203,6 @@ class UnityTestCase(AutopilotTestCase):
257 if self._data_dirs_mock_enabled:
203 if self._data_dirs_mock_enabled:
258 self._patch_data_dirs()
204 self._patch_data_dirs()
259
205
260− # FIXME: we shouldn't be doing this
261− # $MIR_SOCKET, fallback to $XDG_RUNTIME_DIR/mir_socket and
262− # /tmp/mir_socket as last resort
263− try:
264− os.unlink(
265− os.getenv('MIR_SOCKET',
266− os.path.join(os.getenv('XDG_RUNTIME_DIR', "/tmp"),
267− "mir_socket")))
268− except OSError:
269− pass
270− try:
271− os.unlink("/tmp/mir_socket")
272− except OSError:
273− pass
274−
275 unity8_cli_args_list = ["--mode={}".format(mode)]
206 unity8_cli_args_list = ["--mode={}".format(mode)]
276 if len(args) != 0:
207 if len(args) != 0:
277 unity8_cli_args_list += args
208 unity8_cli_args_list += args
@@ -297,26 +228,15 @@ class UnityTestCase(AutopilotTestCase):
297
228
298 def _launch_unity_with_upstart(self, binary_path, args):
229 def _launch_unity_with_upstart(self, binary_path, args):
299 logger.info("Starting unity")
230 logger.info("Starting unity")
231+ self.useFixture(toolkit_fixtures.InitctlEnvironmentVariable(
300− self._patch_environment("QT_LOAD_TESTABILITY", 1)
232+ global_=True, QT_LOAD_TESTABILITY=1))
301−
302− binary_arg = "BINARY=%s" % binary_path
303− extra_args = "ARGS=%s" % " ".join(args)
304− env_args = ["%s=%s" % (k, v) for k, v in self._environment.items()]
305− all_args = [binary_arg, extra_args] + env_args
306
233
307− self.addCleanup(self._cleanup_launching_upstart_unity)
234+ variables = self._environment
308−
235+ variables['ARGS'] = " ".join(args)
309− return process_helpers.restart_unity_with_testability(*all_args)
236+ launch_unity_fixture = fixture_setup.RestartUnityWithTestability(
310−
237+ binary_path, variables)
311− def _cleanup_launching_upstart_unity(self):
238+ self.useFixture(launch_unity_fixture)
312− logger.info("Stopping unity")
239+ return launch_unity_fixture.unity_proxy
313− try:
314− subprocess.check_output(
315− ["/sbin/initctl", "stop", "unity8"],
316− stderr=subprocess.STDOUT
317− )
318− except subprocess.CalledProcessError:
319− logger.warning("Appears unity was already stopped!")
320
240
321 def _patch_data_dirs(self):
241 def _patch_data_dirs(self):
322 data_dirs = get_data_dirs(self._data_dirs_mock_enabled)
242 data_dirs = get_data_dirs(self._data_dirs_mock_enabled)