on xenial help sign in
Move stopping/starting original Unity to be class startup/teardown
bf08b07Christopher Lee
tests/autopilot/unity8/shell/tests/__init__.py+40−31
@@ -69,7 +69,7 @@ def _get_device_emulation_scenarios(devices='All'):
69 elif devices == 'Nexus10':
69 elif devices == 'Nexus10':
70 return [nexus10]
70 return [nexus10]
71 else:
71 else:
72− raise RuntimeException('Unrecognized device-option "%s" passed.' % devices)
72+ raise RuntimeError('Unrecognized device-option "%s" passed.' % devices)
73 else:
73 else:
74 return [native]
74 return [native]
75
75
@@ -77,6 +77,32 @@ class UnityTestCase(AutopilotTestCase):
77
77
78 """A test case base class for the Unity shell tests."""
78 """A test case base class for the Unity shell tests."""
79
79
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+
80 def setUp(self):
106 def setUp(self):
81 super(UnityTestCase, self).setUp()
107 super(UnityTestCase, self).setUp()
82 if Gio is not None and UNITYSHELL_GSETTINGS_SCHEMA in Gio.Settings.list_relocatable_schemas():
108 if Gio is not None and UNITYSHELL_GSETTINGS_SCHEMA in Gio.Settings.list_relocatable_schemas():
@@ -89,6 +115,12 @@ class UnityTestCase(AutopilotTestCase):
89 self._proxy = None
115 self._proxy = None
90 self._lightdm_mock_type = None
116 self._lightdm_mock_type = None
91 self._qml_mock_enabled = True
117 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+
92 self.touch = Touch.create()
124 self.touch = Touch.create()
93 self._setup_display_details()
125 self._setup_display_details()
94
126
@@ -164,7 +196,7 @@ class UnityTestCase(AutopilotTestCase):
164 "/sbin/initctl",
196 "/sbin/initctl",
165 "get-env",
197 "get-env",
166 key
198 key
167− ])
199+ ]).rstrip()
168 except subprocess.CalledProcessError:
200 except subprocess.CalledProcessError:
169 current_value = None
201 current_value = None
170
202
@@ -237,30 +269,12 @@ class UnityTestCase(AutopilotTestCase):
237 return app_proxy
269 return app_proxy
238
270
239 def _launch_unity_with_upstart(self):
271 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− ])
247
272
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"])
273+ subprocess.call(["/sbin/initctl", "set-env", "QT_LOAD_TESTABILITY=1"])
253− except subprocess.CalledProcessError as e:
254− logger.warning("Unable to stop unity8")
255− e.args += ("Failed to stop existing unity8 process", )
256− raise
257
274
258 output = subprocess.check_output(["/sbin/initctl", "start", "unity8"])
275 output = subprocess.check_output(["/sbin/initctl", "start", "unity8"])
259
276
260− self.addCleanup(
261− self._cleanup_launching_upstart_unity,
277+ self.addCleanup(self._cleanup_launching_upstart_unity)
262− unity_already_started
263− )
264
278
265 pid = int(output.split()[-1])
279 pid = int(output.split()[-1])
266
280
@@ -269,20 +283,15 @@ class UnityTestCase(AutopilotTestCase):
269 emulator_base=UnityEmulatorBase,
283 emulator_base=UnityEmulatorBase,
270 )
284 )
271
285
272− def _cleanup_launching_upstart_unity(self, restart_unity):
286+ def _cleanup_launching_upstart_unity(self):
273− logger.info("Cleaning up launching unity, unsetting env")
287+ logger.info("Cleaning up launching unity")
274 subprocess.call(["/sbin/initctl", "unset-env", "QT_LOAD_TESTABILITY"])
288 subprocess.call(["/sbin/initctl", "unset-env", "QT_LOAD_TESTABILITY"])
275
289
276 try:
290 try:
277− logger.info("Stopping existing unity")
291+ logger.info("Stopping unity")
278 subprocess.check_call(["/sbin/initctl", "stop", "unity8"])
292 subprocess.check_call(["/sbin/initctl", "stop", "unity8"])
279 except subprocess.CalledProcessError:
293 except subprocess.CalledProcessError:
280− logger.warning("Appears unity was already stopped")
294+ 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"])
286
295
287 def patch_lightdm_mock(self, mock_type='single'):
296 def patch_lightdm_mock(self, mock_type='single'):
288 self._lightdm_mock_type = mock_type
297 self._lightdm_mock_type = mock_type