@@ -24,17 +24,17 @@ try:
24except ImportError:
24except ImportError:
25 Gio = None
25 Gio = None
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
37from testtools.matchers import Equals
35from testtools.matchers import Equals
37+import ubuntuuitoolkit
38from ubuntuuitoolkit import (
38from ubuntuuitoolkit import (
39 fixture_setup as toolkit_fixtures,
39 fixture_setup as toolkit_fixtures,
40 ubuntu_scenarios
40 ubuntu_scenarios
@@ -51,7 +51,6 @@ from unity8 import (
51 fixture_setup,
51 fixture_setup,
52 process_helpers
52 process_helpers
54−from unity8.shell import emulators
55from unity8.shell.emulators import (
54from unity8.shell.emulators import (
56 dash as dash_helpers,
55 dash as dash_helpers,
57 main_window as main_window_emulator,
56 main_window as main_window_emulator,
@@ -93,36 +92,25 @@ class UnityTestCase(AutopilotTestCase):
93 @classmethod
92 @classmethod
94 def setUpClass(cls):
93 def setUpClass(cls):
96− output = subprocess.check_output(
95+ is_unity_running = process_helpers.is_job_running('unity8')
97− ["/sbin/initctl", "status", "unity8"],
96+ except process_helpers.JobError as e:
98− stderr=subprocess.STDOUT,
97+ xdg_config_home = os.getenv(
99− universal_newlines=True,
98+ 'XDG_CONFIG_HOME', os.path.join(os.getenv('HOME'), '.config'))
100− )
99+ upstart_config_path = os.path.join(xdg_config_home, 'upstart')
101− except subprocess.CalledProcessError as e:
100+ logger.error(
103− "Error: `initctl status unity8` failed, most probably the "
101+ '`initctl status unity8` failed, most probably the '
104− "unity8 session could not be found:\n\n"
102+ 'unity8 session could not be found:\n\n'
106− "Please install unity8 or copy data/unity8.conf to "
104+ 'Please install unity8 or copy data/unity8.conf to '
107− "{1}\n".format(
105+ '{1}\n'.format(e.output, upstart_config_path)
109− os.path.join(os.getenv("XDG_CONFIG_HOME",
110− os.path.join(os.getenv("HOME"),
118− if "start/" in output:
120− "Error: Unity is currently running, these tests require it to "
122− "Please run this command before running these tests: \n"
123− "initctl stop unity8\n"
125− sys.exit(2)
107+ raise e
109+ assert not is_unity_running, (
110+ 'Unity is currently running, these tests require it to be '
112+ 'Please run this command before running these tests: \n'
113+ 'initctl stop unity8\n')
127 def setUp(self):
115 def setUp(self):
128 super().setUp()
116 super().setUp()
@@ -134,13 +122,6 @@ class UnityTestCase(AutopilotTestCase):
134 self._data_dirs_mock_enabled = True
122 self._data_dirs_mock_enabled = True
135 self._environment = {}
123 self._environment = {}
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)
143− self.touch = Touch.create()
144 self._setup_display_details()
125 self._setup_display_details()
146 def _setup_display_details(self):
127 def _setup_display_details(self):
@@ -196,40 +177,6 @@ class UnityTestCase(AutopilotTestCase):
196 divisor = divisor * 2
177 divisor = divisor * 2
197 return divisor
178 return divisor
199− def _patch_environment(self, key, value):
200− """Wrapper for patching env for upstart environment."""
202− current_value = subprocess.check_output(
203− ["/sbin/initctl", "get-env", "--global", key],
204− stderr=subprocess.STDOUT,
205− universal_newlines=True,
207− except subprocess.CalledProcessError:
208− current_value = None
214− "%s=%s" % (key, value)
215− ], stderr=subprocess.STDOUT)
216− self.addCleanup(self._upstart_reset_env, key, current_value)
218− def _upstart_reset_env(self, key, value):
219− logger.info("Resetting upstart env %s to %s", key, value)
222− ["/sbin/initctl", "unset-env", key],
223− stderr=subprocess.STDOUT,
230− "%s=%s" % (key, value)
231− ], stderr=subprocess.STDOUT)
233 def launch_unity(self, mode="full-greeter", *args):
180 def launch_unity(self, mode="full-greeter", *args):
235 Launch the unity shell, return a proxy object for it.
182 Launch the unity shell, return a proxy object for it.
@@ -257,21 +204,6 @@ class UnityTestCase(AutopilotTestCase):
257 if self._data_dirs_mock_enabled:
204 if self._data_dirs_mock_enabled:
258 self._patch_data_dirs()
205 self._patch_data_dirs()
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
265− os.getenv('MIR_SOCKET',
266− os.path.join(os.getenv('XDG_RUNTIME_DIR', "/tmp"),
271− os.unlink("/tmp/mir_socket")
275 unity8_cli_args_list = ["--mode={}".format(mode)]
207 unity8_cli_args_list = ["--mode={}".format(mode)]
276 if len(args) != 0:
208 if len(args) != 0:
277 unity8_cli_args_list += args
209 unity8_cli_args_list += args
@@ -297,26 +229,15 @@ class UnityTestCase(AutopilotTestCase):
298 def _launch_unity_with_upstart(self, binary_path, args):
230 def _launch_unity_with_upstart(self, binary_path, args):
299 logger.info("Starting unity")
231 logger.info("Starting unity")
232+ self.useFixture(toolkit_fixtures.InitctlEnvironmentVariable(
300− self._patch_environment("QT_LOAD_TESTABILITY", 1)
233+ global_=True, QT_LOAD_TESTABILITY=1))
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
307− self.addCleanup(self._cleanup_launching_upstart_unity)
235+ variables = self._environment
308−
236+ variables['ARGS'] = " ".join(args)
309− return process_helpers.restart_unity_with_testability(*all_args)
237+ launch_unity_fixture = fixture_setup.RestartUnityWithTestability(
310−
238+ binary_path, variables)
311− def _cleanup_launching_upstart_unity(self):
239+ self.useFixture(launch_unity_fixture)
312− logger.info("Stopping unity")
240+ return launch_unity_fixture.unity_proxy
314− subprocess.check_output(
315− ["/sbin/initctl", "stop", "unity8"],
316− stderr=subprocess.STDOUT
318− except subprocess.CalledProcessError:
319− logger.warning("Appears unity was already stopped!")
321 def _patch_data_dirs(self):
242 def _patch_data_dirs(self):
322 data_dirs = get_data_dirs(self._data_dirs_mock_enabled)
243 data_dirs = get_data_dirs(self._data_dirs_mock_enabled)
@@ -369,7 +290,7 @@ class UnityTestCase(AutopilotTestCase):
369 pid = process_helpers.get_job_pid('unity8-dash')
290 pid = process_helpers.get_job_pid('unity8-dash')
370 dash_proxy = introspection.get_proxy_object_for_existing_process(
291 dash_proxy = introspection.get_proxy_object_for_existing_process(
372− emulator_base=emulators.UnityEmulatorBase,
293+ emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase
374 dash_app = dash_helpers.DashApp(dash_proxy)
295 dash_app = dash_helpers.DashApp(dash_proxy)
375 return dash_app.dash
296 return dash_app.dash