@@ -69,7 +69,7 @@ def _get_device_emulation_scenarios(devices='All'):
6969 elif devices == 'Nexus10':
7070 return [nexus10]
7171 else:
72− raise RuntimeException('Unrecognized device-option "%s" passed.' % devices)
72+ raise RuntimeError('Unrecognized device-option "%s" passed.' % devices)
7373 else:
7474 return [native]
7575
@@ -77,6 +77,32 @@ class UnityTestCase(AutopilotTestCase):
7777
7878 """A test case base class for the Unity shell tests."""
7979
80+ __unity_was_running_before_tests = False
81+
82+ @classmethod
83+ def setUpClass(cls):
84+ output = subprocess.check_output([
85+ "/sbin/initctl",
86+ "status",
87+ "unity8"
88+ ])
89+
90+ if "start/" in output:
91+ UnityTestCase.__unity_was_running_before_tests = True
92+ logger.info("Stopping existing Unity")
93+ try:
94+ subprocess.check_call(["/sbin/initctl", "stop", "unity8"])
95+ except subprocess.CalledProcessError as e:
96+ logger.warning("Unable to stop unity8")
97+ e.args += ("Failed to stop existing unity8 process", )
98+ raise
99+
100+ @classmethod
101+ def tearDownClass(cls):
102+ if UnityTestCase.__unity_was_running_before_tests:
103+ logger.info("Starting unity again with original env")
104+ subprocess.check_call(["/sbin/initctl", "start", "unity8"])
105+
80106 def setUp(self):
81107 super(UnityTestCase, self).setUp()
82108 if Gio is not None and UNITYSHELL_GSETTINGS_SCHEMA in Gio.Settings.list_relocatable_schemas():
@@ -89,6 +115,12 @@ class UnityTestCase(AutopilotTestCase):
89115 self._proxy = None
90116 self._lightdm_mock_type = None
91117 self._qml_mock_enabled = True
118+
119+ #### This is a work around re: lp:1238417 ####
120+ from autopilot.input import _uinput
121+ _uinput._touch_device = _uinput.create_touch_device()
122+ ####
123+
92124 self.touch = Touch.create()
93125 self._setup_display_details()
94126
@@ -164,7 +196,7 @@ class UnityTestCase(AutopilotTestCase):
164196 "/sbin/initctl",
165197 "get-env",
166198 key
167− ])
199+ ]).rstrip()
168200 except subprocess.CalledProcessError:
169201 current_value = None
170202
@@ -237,30 +269,12 @@ class UnityTestCase(AutopilotTestCase):
237269 return app_proxy
238270
239271 def _launch_unity_with_upstart(self):
240− subprocess.call(["/sbin/initctl", "set-env", "QT_LOAD_TESTABILITY=1"])
241−
242− output = subprocess.check_output([
243− "/sbin/initctl",
244− "status",
245− "unity8"
246− ])
247272
248− unity_already_started = False
249− if "start/" in output:
250− unity_already_started = True
251− try:
252− subprocess.check_call(["/sbin/initctl", "stop", "unity8"])
253− except subprocess.CalledProcessError as e:
254− logger.warning("Unable to stop unity8")
255− e.args += ("Failed to stop existing unity8 process", )
256− raise
273+ subprocess.call(["/sbin/initctl", "set-env", "QT_LOAD_TESTABILITY=1"])
257274
258275 output = subprocess.check_output(["/sbin/initctl", "start", "unity8"])
259276
260− self.addCleanup(
261− self._cleanup_launching_upstart_unity,
262− unity_already_started
263− )
277+ self.addCleanup(self._cleanup_launching_upstart_unity)
264278
265279 pid = int(output.split()[-1])
266280
@@ -269,20 +283,15 @@ class UnityTestCase(AutopilotTestCase):
269283 emulator_base=UnityEmulatorBase,
270284 )
271285
272− def _cleanup_launching_upstart_unity(self, restart_unity):
273− logger.info("Cleaning up launching unity, unsetting env")
286+ def _cleanup_launching_upstart_unity(self):
287+ logger.info("Cleaning up launching unity")
274288 subprocess.call(["/sbin/initctl", "unset-env", "QT_LOAD_TESTABILITY"])
275289
276290 try:
277− logger.info("Stopping existing unity")
291+ logger.info("Stopping unity")
278292 subprocess.check_call(["/sbin/initctl", "stop", "unity8"])
279293 except subprocess.CalledProcessError:
280− logger.warning("Appears unity was already stopped")
281−
282− # Actually, the previous env stuff will be still here right?
283− if restart_unity:
284− logger.info("Starting unity again with original env")
285− subprocess.check_call(["/sbin/initctl", "start", "unity8"])
294+ logger.warning("Appears unity was already stopped!")
286295
287296 def patch_lightdm_mock(self, mock_type='single'):
288297 self._lightdm_mock_type = mock_type