Merge lp:~dobey/autopilot/drop-ual into lp:autopilot/legacy
- drop-ual
- Merge into legacy
Proposed by
dobey
Status: | Merged |
---|---|
Approved by: | dobey |
Approved revision: | 501 |
Merged at revision: | 501 |
Proposed branch: | lp:~dobey/autopilot/drop-ual |
Merge into: | lp:autopilot/legacy |
Diff against target: |
883 lines (+1/-771) 5 files modified
autopilot/application/__init__.py (+0/-4) autopilot/application/_launcher.py (+1/-167) autopilot/testcase.py (+0/-82) autopilot/tests/unit/test_application_launcher.py (+0/-516) debian/control (+0/-2) |
To merge this branch: | bzr merge lp:~dobey/autopilot/drop-ual |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
dobey (community) | Approve | ||
Review via email: mp+318968@code.launchpad.net |
Commit message
Remove support for UAL from legacy code, as it's not needed.
Description of the change
To post a comment you must log in.
lp:~dobey/autopilot/drop-ual
updated
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'autopilot/application/__init__.py' |
2 | --- autopilot/application/__init__.py 2014-01-24 04:18:10 +0000 |
3 | +++ autopilot/application/__init__.py 2017-03-03 23:28:24 +0000 |
4 | @@ -20,15 +20,11 @@ |
5 | """Base package for application launching and environment management.""" |
6 | |
7 | from autopilot.application._launcher import ( |
8 | - ClickApplicationLauncher, |
9 | get_application_launcher_wrapper, |
10 | NormalApplicationLauncher, |
11 | - UpstartApplicationLauncher, |
12 | ) |
13 | |
14 | __all__ = [ |
15 | - 'ClickApplicationLauncher', |
16 | 'get_application_launcher_wrapper', |
17 | 'NormalApplicationLauncher', |
18 | - 'UpstartApplicationLauncher', |
19 | ] |
20 | |
21 | === modified file 'autopilot/application/_launcher.py' |
22 | --- autopilot/application/_launcher.py 2014-08-06 05:39:37 +0000 |
23 | +++ autopilot/application/_launcher.py 2017-03-03 23:28:24 +0000 |
24 | @@ -20,7 +20,7 @@ |
25 | """Base module for application launchers.""" |
26 | |
27 | import fixtures |
28 | -from gi.repository import GLib, UbuntuAppLaunch |
29 | +from gi.repository import GLib |
30 | import json |
31 | import logging |
32 | import os |
33 | @@ -55,143 +55,6 @@ |
34 | raise NotImplementedError("Sub-classes must implement this method.") |
35 | |
36 | |
37 | -class UpstartApplicationLauncher(ApplicationLauncher): |
38 | - |
39 | - """A launcher class that launched applicaitons with UpstartAppLaunch.""" |
40 | - |
41 | - Timeout = object() |
42 | - Failed = object() |
43 | - Started = object() |
44 | - Stopped = object() |
45 | - |
46 | - def __init__(self, case_addDetail, **kwargs): |
47 | - super(UpstartApplicationLauncher, self).__init__(case_addDetail) |
48 | - |
49 | - self.emulator_base = kwargs.pop('emulator_base', None) |
50 | - self.dbus_bus = kwargs.pop('dbus_bus', 'session') |
51 | - self.dbus_application_name = kwargs.pop('application_name', None) |
52 | - |
53 | - _raise_on_unknown_kwargs(kwargs) |
54 | - |
55 | - def launch(self, app_id, app_uris=[]): |
56 | - state = {} |
57 | - state['loop'] = self._get_glib_loop() |
58 | - state['expected_app_id'] = app_id |
59 | - state['message'] = '' |
60 | - |
61 | - UbuntuAppLaunch.observer_add_app_failed(self._on_failed, state) |
62 | - UbuntuAppLaunch.observer_add_app_started(self._on_started, state) |
63 | - UbuntuAppLaunch.observer_add_app_focus(self._on_started, state) |
64 | - GLib.timeout_add_seconds(10.0, self._on_timeout, state) |
65 | - |
66 | - self._launch_app(app_id, app_uris) |
67 | - state['loop'].run() |
68 | - UbuntuAppLaunch.observer_delete_app_failed(self._on_failed) |
69 | - UbuntuAppLaunch.observer_delete_app_started(self._on_started) |
70 | - UbuntuAppLaunch.observer_delete_app_focus(self._on_started) |
71 | - self._maybe_add_application_cleanups(state) |
72 | - self._check_status_error( |
73 | - state.get('status', None), |
74 | - state.get('message', '') |
75 | - ) |
76 | - return self._get_pid_for_launched_app(app_id) |
77 | - |
78 | - @staticmethod |
79 | - def _on_failed(launched_app_id, failure_type, state): |
80 | - if launched_app_id == state['expected_app_id']: |
81 | - if failure_type == UbuntuAppLaunch.AppFailed.CRASH: |
82 | - state['message'] = 'Application crashed.' |
83 | - elif failure_type == UbuntuAppLaunch.AppFailed.START_FAILURE: |
84 | - state['message'] = 'Application failed to start.' |
85 | - state['status'] = UpstartApplicationLauncher.Failed |
86 | - state['loop'].quit() |
87 | - |
88 | - @staticmethod |
89 | - def _on_started(launched_app_id, state): |
90 | - if launched_app_id == state['expected_app_id']: |
91 | - state['status'] = UpstartApplicationLauncher.Started |
92 | - state['loop'].quit() |
93 | - |
94 | - @staticmethod |
95 | - def _on_stopped(stopped_app_id, state): |
96 | - if stopped_app_id == state['expected_app_id']: |
97 | - state['status'] = UpstartApplicationLauncher.Stopped |
98 | - state['loop'].quit() |
99 | - |
100 | - @staticmethod |
101 | - def _on_timeout(state): |
102 | - state['status'] = UpstartApplicationLauncher.Timeout |
103 | - state['loop'].quit() |
104 | - |
105 | - def _maybe_add_application_cleanups(self, state): |
106 | - if state.get('status', None) == UpstartApplicationLauncher.Started: |
107 | - app_id = state['expected_app_id'] |
108 | - self.addCleanup(self._stop_application, app_id) |
109 | - self.addCleanup(self._attach_application_log, app_id) |
110 | - |
111 | - def _attach_application_log(self, app_id): |
112 | - log_path = UbuntuAppLaunch.application_log_path(app_id) |
113 | - if log_path: |
114 | - self.case_addDetail( |
115 | - "Application Log", |
116 | - content_from_file(log_path) |
117 | - ) |
118 | - |
119 | - def _stop_application(self, app_id): |
120 | - state = {} |
121 | - state['loop'] = self._get_glib_loop() |
122 | - state['expected_app_id'] = app_id |
123 | - |
124 | - UbuntuAppLaunch.observer_add_app_stop(self._on_stopped, state) |
125 | - GLib.timeout_add_seconds(10.0, self._on_timeout, state) |
126 | - |
127 | - UbuntuAppLaunch.stop_application(app_id) |
128 | - state['loop'].run() |
129 | - UbuntuAppLaunch.observer_delete_app_stop(self._on_stopped) |
130 | - |
131 | - if state.get('status', None) == UpstartApplicationLauncher.Timeout: |
132 | - _logger.error( |
133 | - "Timed out waiting for Application with app_id '%s' to stop.", |
134 | - app_id |
135 | - ) |
136 | - |
137 | - @staticmethod |
138 | - def _get_glib_loop(): |
139 | - return GLib.MainLoop() |
140 | - |
141 | - @staticmethod |
142 | - def _get_pid_for_launched_app(app_id): |
143 | - return UbuntuAppLaunch.get_primary_pid(app_id) |
144 | - |
145 | - @staticmethod |
146 | - def _launch_app(app_name, app_uris): |
147 | - UbuntuAppLaunch.start_application_test(app_name, app_uris) |
148 | - |
149 | - @staticmethod |
150 | - def _check_status_error(status, extra_message=''): |
151 | - message_parts = [] |
152 | - if status == UpstartApplicationLauncher.Timeout: |
153 | - message_parts.append( |
154 | - "Timed out while waiting for application to launch" |
155 | - ) |
156 | - elif status == UpstartApplicationLauncher.Failed: |
157 | - message_parts.append("Application Launch Failed") |
158 | - if message_parts and extra_message: |
159 | - message_parts.append(extra_message) |
160 | - if message_parts: |
161 | - raise RuntimeError(': '.join(message_parts)) |
162 | - |
163 | - |
164 | -class ClickApplicationLauncher(UpstartApplicationLauncher): |
165 | - |
166 | - def launch(self, package_id, app_name, app_uris): |
167 | - app_id = _get_click_app_id(package_id, app_name) |
168 | - return self._do_upstart_launch(app_id, app_uris) |
169 | - |
170 | - def _do_upstart_launch(self, app_id, app_uris): |
171 | - return super(ClickApplicationLauncher, self).launch(app_id, app_uris) |
172 | - |
173 | - |
174 | class NormalApplicationLauncher(ApplicationLauncher): |
175 | def __init__(self, case_addDetail, **kwargs): |
176 | super(NormalApplicationLauncher, self).__init__(case_addDetail) |
177 | @@ -269,35 +132,6 @@ |
178 | return process |
179 | |
180 | |
181 | -def _get_click_app_id(package_id, app_name=None): |
182 | - for pkg in _get_click_manifest(): |
183 | - if pkg['name'] == package_id: |
184 | - if app_name is None: |
185 | - # py3 dict.keys isn't indexable. |
186 | - app_name = list(pkg['hooks'].keys())[0] |
187 | - elif app_name not in pkg['hooks']: |
188 | - raise RuntimeError( |
189 | - "Application '{}' is not present within the click " |
190 | - "package '{}'.".format(app_name, package_id)) |
191 | - |
192 | - return "{0}_{1}_{2}".format(package_id, app_name, pkg['version']) |
193 | - raise RuntimeError( |
194 | - "Unable to find package '{}' in the click manifest." |
195 | - .format(package_id) |
196 | - ) |
197 | - |
198 | - |
199 | -def _get_click_manifest(): |
200 | - """Return the click package manifest as a python list.""" |
201 | - # get the whole click package manifest every time - it seems fast enough |
202 | - # but this is a potential optimisation point for the future: |
203 | - click_manifest_str = subprocess.check_output( |
204 | - ["click", "list", "--manifest"], |
205 | - universal_newlines=True |
206 | - ) |
207 | - return json.loads(click_manifest_str) |
208 | - |
209 | - |
210 | def _get_application_environment(app_type=None, app_path=None): |
211 | if app_type is None and app_path is None: |
212 | raise ValueError("Must specify either app_type or app_path.") |
213 | |
214 | === modified file 'autopilot/testcase.py' |
215 | --- autopilot/testcase.py 2014-08-06 05:39:37 +0000 |
216 | +++ autopilot/testcase.py 2017-03-03 23:28:24 +0000 |
217 | @@ -57,10 +57,8 @@ |
218 | from testtools.matchers import Equals |
219 | |
220 | from autopilot.application import ( |
221 | - ClickApplicationLauncher, |
222 | get_application_launcher_wrapper, |
223 | NormalApplicationLauncher, |
224 | - UpstartApplicationLauncher, |
225 | ) |
226 | from autopilot.display import Display |
227 | from autopilot.globals import get_debug_profile_fixture |
228 | @@ -263,86 +261,6 @@ |
229 | |
230 | return self._launch_test_application(launcher, application, *arguments) |
231 | |
232 | - def launch_click_package(self, package_id, app_name=None, app_uris=[], |
233 | - **kwargs): |
234 | - """Launch a click package application with introspection enabled. |
235 | - |
236 | - This method takes care of launching a click package with introspection |
237 | - exabled. You probably want to use this method if your application is |
238 | - packaged in a click application, or is started via upstart. |
239 | - |
240 | - Usage is similar to the |
241 | - :py:meth:`AutopilotTestCase.launch_test_application`:: |
242 | - |
243 | - app_proxy = self.launch_click_package( |
244 | - "com.ubuntu.dropping-letters" |
245 | - ) |
246 | - |
247 | - :param package_id: The Click package name you want to launch. For |
248 | - example: ``com.ubuntu.dropping-letters`` |
249 | - :param app_name: Currently, only one application can be packaged in a |
250 | - click package, and this parameter can be left at None. If |
251 | - specified, it should be the application name you wish to launch. |
252 | - :param app_uris: Parameters used to launch the click package. This |
253 | - parameter will be left empty if not used. |
254 | - |
255 | - :keyword emulator_base: If set, specifies the base class to be used for |
256 | - all emulators for this loaded application. |
257 | - |
258 | - :raises RuntimeError: If the specified package_id cannot be found in |
259 | - the click package manifest. |
260 | - :raises RuntimeError: If the specified app_name cannot be found within |
261 | - the specified click package. |
262 | - |
263 | - :returns: proxy object for the launched package application |
264 | - |
265 | - """ |
266 | - if isinstance(app_uris, (six.text_type, six.binary_type)): |
267 | - app_uris = [app_uris] |
268 | - _logger.info( |
269 | - "Attempting to launch click application '%s' from click package " |
270 | - " '%s' and URIs '%s'", |
271 | - app_name if app_name is not None else "(default)", |
272 | - package_id, |
273 | - ','.join(app_uris) |
274 | - ) |
275 | - launcher = self.useFixture( |
276 | - ClickApplicationLauncher(self.addDetail, **kwargs) |
277 | - ) |
278 | - return self._launch_test_application(launcher, package_id, app_name, |
279 | - app_uris) |
280 | - |
281 | - def launch_upstart_application(self, application_name, uris=[], **kwargs): |
282 | - """Launch an application with upstart. |
283 | - |
284 | - This method launched an application via the ``ubuntu-app-launch`` |
285 | - library, on platforms that support it. |
286 | - |
287 | - Usage is similar to the |
288 | - :py:meth:`AutopilotTestCase.launch_test_application`:: |
289 | - |
290 | - app_proxy = self.launch_upstart_application("gallery-app") |
291 | - |
292 | - :param application_name: The name of the application to launch. |
293 | - :keyword emulator_base: If set, specifies the base class to be used for |
294 | - all emulators for this loaded application. |
295 | - |
296 | - :raises RuntimeError: If the specified application cannot be launched. |
297 | - :raises ValueError: If unknown keyword arguments are specified. |
298 | - """ |
299 | - if isinstance(uris, (six.text_type, six.binary_type)): |
300 | - uris = [uris] |
301 | - _logger.info( |
302 | - "Attempting to launch application '%s' with URIs '%s' via " |
303 | - "upstart-app-launch", |
304 | - application_name, |
305 | - ','.join(uris) |
306 | - ) |
307 | - launcher = self.useFixture( |
308 | - UpstartApplicationLauncher(self.addDetail, **kwargs) |
309 | - ) |
310 | - return self._launch_test_application(launcher, application_name, uris) |
311 | - |
312 | # Wrapper function tying the newer ApplicationLauncher behaviour with the |
313 | # previous (to be depreciated) behaviour |
314 | def _launch_test_application(self, launcher_instance, application, *args): |
315 | |
316 | === modified file 'autopilot/tests/unit/test_application_launcher.py' |
317 | --- autopilot/tests/unit/test_application_launcher.py 2014-08-06 05:39:37 +0000 |
318 | +++ autopilot/tests/unit/test_application_launcher.py 2017-03-03 23:28:24 +0000 |
319 | @@ -42,9 +42,7 @@ |
320 | from mock import Mock, patch |
321 | |
322 | from autopilot.application import ( |
323 | - ClickApplicationLauncher, |
324 | NormalApplicationLauncher, |
325 | - UpstartApplicationLauncher, |
326 | ) |
327 | from autopilot.application._environment import ( |
328 | GtkApplicationEnvironment, |
329 | @@ -59,8 +57,6 @@ |
330 | _get_app_env_from_string_hint, |
331 | _get_application_environment, |
332 | _get_application_path, |
333 | - _get_click_app_id, |
334 | - _get_click_manifest, |
335 | _is_process_running, |
336 | _kill_process, |
337 | ) |
338 | @@ -171,500 +167,6 @@ |
339 | ) |
340 | |
341 | |
342 | -class ClickApplicationLauncherTests(TestCase): |
343 | - |
344 | - def test_raises_exception_on_unknown_kwargs(self): |
345 | - self.assertThat( |
346 | - lambda: ClickApplicationLauncher(self.addDetail, unknown=True), |
347 | - raises(ValueError("Unknown keyword arguments: 'unknown'.")) |
348 | - ) |
349 | - |
350 | - def test_application_name_kwarg_stored(self): |
351 | - app_name = self.getUniqueString() |
352 | - launcher = ClickApplicationLauncher( |
353 | - self.addDetail, |
354 | - application_name=app_name |
355 | - ) |
356 | - |
357 | - self.assertThat( |
358 | - launcher.dbus_application_name, Equals(app_name) |
359 | - ) |
360 | - |
361 | - def test_click_launch_calls_upstart_launch(self): |
362 | - launcher = ClickApplicationLauncher(self.addDetail) |
363 | - token = self.getUniqueString() |
364 | - with patch.object(launcher, '_do_upstart_launch') as p_dul: |
365 | - with patch.object(_l, '_get_click_app_id') as p_gcai: |
366 | - p_gcai.return_value = token |
367 | - launcher.launch('some_app_id', 'some_app_name', []) |
368 | - p_dul.assert_called_once_with(token, []) |
369 | - |
370 | - def test_upcalls_to_upstart(self): |
371 | - class FakeUpstartBase(_l.ApplicationLauncher): |
372 | - launch_call_args = [] |
373 | - |
374 | - def launch(self, *args): |
375 | - FakeUpstartBase.launch_call_args = list(args) |
376 | - |
377 | - patcher = patch.object( |
378 | - _l.ClickApplicationLauncher, |
379 | - '__bases__', |
380 | - (FakeUpstartBase,) |
381 | - ) |
382 | - with patcher: |
383 | - # Prevent mock from trying to delete __bases__ |
384 | - patcher.is_local = True |
385 | - launcher = ClickApplicationLauncher(self.addDetail) |
386 | - launcher._do_upstart_launch('app_id', []) |
387 | - self.assertEqual( |
388 | - FakeUpstartBase.launch_call_args, |
389 | - ['app_id', []]) |
390 | - |
391 | - |
392 | -class ClickFunctionTests(TestCase): |
393 | - |
394 | - def test_get_click_app_id_raises_runtimeerror_on_empty_manifest(self): |
395 | - """_get_click_app_id must raise a RuntimeError if the requested |
396 | - package id is not found in the click manifest. |
397 | - |
398 | - """ |
399 | - with patch.object(_l, '_get_click_manifest', return_value=[]): |
400 | - self.assertThat( |
401 | - lambda: _get_click_app_id("com.autopilot.testing"), |
402 | - raises( |
403 | - RuntimeError( |
404 | - "Unable to find package 'com.autopilot.testing' in " |
405 | - "the click manifest." |
406 | - ) |
407 | - ) |
408 | - ) |
409 | - |
410 | - def test_get_click_app_id_raises_runtimeerror_on_missing_package(self): |
411 | - with patch.object(_l, '_get_click_manifest') as cm: |
412 | - cm.return_value = [ |
413 | - { |
414 | - 'name': 'com.not.expected.name', |
415 | - 'hooks': {'bar': {}}, 'version': '1.0' |
416 | - } |
417 | - ] |
418 | - |
419 | - self.assertThat( |
420 | - lambda: _get_click_app_id("com.autopilot.testing"), |
421 | - raises( |
422 | - RuntimeError( |
423 | - "Unable to find package 'com.autopilot.testing' in " |
424 | - "the click manifest." |
425 | - ) |
426 | - ) |
427 | - ) |
428 | - |
429 | - def test_get_click_app_id_raises_runtimeerror_on_wrong_app(self): |
430 | - """get_click_app_id must raise a RuntimeError if the requested |
431 | - application is not found within the click package. |
432 | - |
433 | - """ |
434 | - with patch.object(_l, '_get_click_manifest') as cm: |
435 | - cm.return_value = [{'name': 'com.autopilot.testing', 'hooks': {}}] |
436 | - |
437 | - self.assertThat( |
438 | - lambda: _get_click_app_id("com.autopilot.testing", "bar"), |
439 | - raises( |
440 | - RuntimeError( |
441 | - "Application 'bar' is not present within the click " |
442 | - "package 'com.autopilot.testing'." |
443 | - ) |
444 | - ) |
445 | - ) |
446 | - |
447 | - def test_get_click_app_id_returns_id(self): |
448 | - with patch.object(_l, '_get_click_manifest') as cm: |
449 | - cm.return_value = [ |
450 | - { |
451 | - 'name': 'com.autopilot.testing', |
452 | - 'hooks': {'bar': {}}, 'version': '1.0' |
453 | - } |
454 | - ] |
455 | - |
456 | - self.assertThat( |
457 | - _get_click_app_id("com.autopilot.testing", "bar"), |
458 | - Equals("com.autopilot.testing_bar_1.0") |
459 | - ) |
460 | - |
461 | - def test_get_click_app_id_returns_id_without_appid_passed(self): |
462 | - with patch.object(_l, '_get_click_manifest') as cm: |
463 | - cm.return_value = [ |
464 | - { |
465 | - 'name': 'com.autopilot.testing', |
466 | - 'hooks': {'bar': {}}, 'version': '1.0' |
467 | - } |
468 | - ] |
469 | - |
470 | - self.assertThat( |
471 | - _get_click_app_id("com.autopilot.testing"), |
472 | - Equals("com.autopilot.testing_bar_1.0") |
473 | - ) |
474 | - |
475 | - |
476 | -class UpstartApplicationLauncherTests(TestCase): |
477 | - |
478 | - def test_can_construct_UpstartApplicationLauncher(self): |
479 | - UpstartApplicationLauncher(self.addDetail) |
480 | - |
481 | - def test_default_values_are_set(self): |
482 | - launcher = UpstartApplicationLauncher(self.addDetail) |
483 | - self.assertThat(launcher.emulator_base, Equals(None)) |
484 | - self.assertThat(launcher.dbus_bus, Equals('session')) |
485 | - |
486 | - def test_can_set_emulator_base(self): |
487 | - mock_emulator_base = Mock() |
488 | - launcher = UpstartApplicationLauncher( |
489 | - self.addDetail, |
490 | - emulator_base=mock_emulator_base |
491 | - ) |
492 | - |
493 | - self.assertThat(launcher.emulator_base, Equals(mock_emulator_base)) |
494 | - |
495 | - def test_can_set_dbus_bus(self): |
496 | - launcher = UpstartApplicationLauncher( |
497 | - self.addDetail, |
498 | - dbus_bus='system' |
499 | - ) |
500 | - |
501 | - self.assertThat(launcher.dbus_bus, Equals('system')) |
502 | - |
503 | - def test_raises_exception_on_unknown_kwargs(self): |
504 | - self.assertThat( |
505 | - lambda: UpstartApplicationLauncher(self.addDetail, unknown=True), |
506 | - raises(ValueError("Unknown keyword arguments: 'unknown'.")) |
507 | - ) |
508 | - |
509 | - def test_on_failed_only_sets_status_on_correct_app_id(self): |
510 | - state = { |
511 | - 'expected_app_id': 'gedit', |
512 | - } |
513 | - |
514 | - UpstartApplicationLauncher._on_failed('some_game', None, state) |
515 | - |
516 | - self.assertThat(state, Not(Contains('status'))) |
517 | - |
518 | - def assertFunctionSetsCorrectStateAndQuits(self, observer, expected_state): |
519 | - """Assert that the observer observer sets the correct state id. |
520 | - |
521 | - :param observer: The observer callable you want to test. |
522 | - :param expected_state: The state id the observer callable must set. |
523 | - |
524 | - """ |
525 | - expected_app_id = self.getUniqueString() |
526 | - state = { |
527 | - 'expected_app_id': expected_app_id, |
528 | - 'loop': Mock() |
529 | - } |
530 | - |
531 | - if observer == UpstartApplicationLauncher._on_failed: |
532 | - observer(expected_app_id, None, state) |
533 | - elif observer == UpstartApplicationLauncher._on_started or \ |
534 | - observer == UpstartApplicationLauncher._on_stopped: |
535 | - observer(expected_app_id, state) |
536 | - else: |
537 | - observer(state) |
538 | - |
539 | - self.assertThat( |
540 | - state['status'], |
541 | - Equals(expected_state) |
542 | - ) |
543 | - state['loop'].quit.assert_called_once_with() |
544 | - |
545 | - def test_on_failed_sets_status_with_correct_app_id(self): |
546 | - self.assertFunctionSetsCorrectStateAndQuits( |
547 | - UpstartApplicationLauncher._on_failed, |
548 | - UpstartApplicationLauncher.Failed |
549 | - ) |
550 | - |
551 | - def test_on_started_sets_status_with_correct_app_id(self): |
552 | - self.assertFunctionSetsCorrectStateAndQuits( |
553 | - UpstartApplicationLauncher._on_started, |
554 | - UpstartApplicationLauncher.Started |
555 | - ) |
556 | - |
557 | - def test_on_timeout_sets_status_and_exits_loop(self): |
558 | - self.assertFunctionSetsCorrectStateAndQuits( |
559 | - UpstartApplicationLauncher._on_timeout, |
560 | - UpstartApplicationLauncher.Timeout |
561 | - ) |
562 | - |
563 | - def test_on_started_only_sets_status_on_correct_app_id(self): |
564 | - state = { |
565 | - 'expected_app_id': 'gedit', |
566 | - } |
567 | - |
568 | - UpstartApplicationLauncher._on_started('some_game', state) |
569 | - |
570 | - self.assertThat(state, Not(Contains('status'))) |
571 | - |
572 | - def test_on_stopped_only_sets_status_on_correct_app_id(self): |
573 | - state = { |
574 | - 'expected_app_id': 'gedit', |
575 | - } |
576 | - |
577 | - UpstartApplicationLauncher._on_stopped('some_game', state) |
578 | - self.assertThat(state, Not(Contains('status'))) |
579 | - |
580 | - def test_on_stopped_sets_status_and_exits_loop(self): |
581 | - self.assertFunctionSetsCorrectStateAndQuits( |
582 | - UpstartApplicationLauncher._on_stopped, |
583 | - UpstartApplicationLauncher.Stopped |
584 | - ) |
585 | - |
586 | - def test_get_pid_calls_upstart_module(self): |
587 | - expected_return = self.getUniqueInteger() |
588 | - with patch.object(_l, 'UbuntuAppLaunch') as mock_ual: |
589 | - mock_ual.get_primary_pid.return_value = expected_return |
590 | - observed = UpstartApplicationLauncher._get_pid_for_launched_app( |
591 | - 'gedit' |
592 | - ) |
593 | - |
594 | - mock_ual.get_primary_pid.assert_called_once_with('gedit') |
595 | - self.assertThat(expected_return, Equals(observed)) |
596 | - |
597 | - def test_launch_app_calls_upstart_module(self): |
598 | - with patch.object(_l, 'UbuntuAppLaunch') as mock_ual: |
599 | - UpstartApplicationLauncher._launch_app( |
600 | - 'gedit', |
601 | - ['some', 'uris'] |
602 | - ) |
603 | - |
604 | - mock_ual.start_application_test.assert_called_once_with( |
605 | - 'gedit', |
606 | - ['some', 'uris'] |
607 | - ) |
608 | - |
609 | - def test_check_error_raises_RuntimeError_on_timeout(self): |
610 | - fn = lambda: UpstartApplicationLauncher._check_status_error( |
611 | - UpstartApplicationLauncher.Timeout |
612 | - ) |
613 | - self.assertThat( |
614 | - fn, |
615 | - raises( |
616 | - RuntimeError( |
617 | - "Timed out while waiting for application to launch" |
618 | - ) |
619 | - ) |
620 | - ) |
621 | - |
622 | - def test_check_error_raises_RuntimeError_on_failure(self): |
623 | - fn = lambda: UpstartApplicationLauncher._check_status_error( |
624 | - UpstartApplicationLauncher.Failed |
625 | - ) |
626 | - self.assertThat( |
627 | - fn, |
628 | - raises( |
629 | - RuntimeError( |
630 | - "Application Launch Failed" |
631 | - ) |
632 | - ) |
633 | - ) |
634 | - |
635 | - def test_check_error_raises_RuntimeError_with_extra_message(self): |
636 | - fn = lambda: UpstartApplicationLauncher._check_status_error( |
637 | - UpstartApplicationLauncher.Failed, |
638 | - "extra message" |
639 | - ) |
640 | - self.assertThat( |
641 | - fn, |
642 | - raises( |
643 | - RuntimeError( |
644 | - "Application Launch Failed: extra message" |
645 | - ) |
646 | - ) |
647 | - ) |
648 | - |
649 | - def test_check_error_does_nothing_on_None(self): |
650 | - UpstartApplicationLauncher._check_status_error(None) |
651 | - |
652 | - def test_get_loop_returns_glib_mainloop_instance(self): |
653 | - loop = UpstartApplicationLauncher._get_glib_loop() |
654 | - self.assertThat(loop, IsInstance(GLib.MainLoop)) |
655 | - |
656 | - def test_launch(self): |
657 | - launcher = UpstartApplicationLauncher(self.addDetail) |
658 | - with patch.object(launcher, '_launch_app') as patched_launch: |
659 | - with patch.object(launcher, '_get_glib_loop'): |
660 | - launcher.launch('gedit') |
661 | - |
662 | - patched_launch.assert_called_once_with('gedit', []) |
663 | - |
664 | - def assertFailedObserverSetsExtraMessage(self, fail_type, expected_msg): |
665 | - """Assert that the on_failed observer must set the expected message |
666 | - for a particular failure_type.""" |
667 | - expected_app_id = self.getUniqueString() |
668 | - state = { |
669 | - 'expected_app_id': expected_app_id, |
670 | - 'loop': Mock() |
671 | - } |
672 | - UpstartApplicationLauncher._on_failed( |
673 | - expected_app_id, |
674 | - fail_type, |
675 | - state |
676 | - ) |
677 | - self.assertEqual(expected_msg, state['message']) |
678 | - |
679 | - def test_on_failed_sets_message_for_app_crash(self): |
680 | - self.assertFailedObserverSetsExtraMessage( |
681 | - _l.UbuntuAppLaunch.AppFailed.CRASH, |
682 | - 'Application crashed.' |
683 | - ) |
684 | - |
685 | - def test_on_failed_sets_message_for_app_start_failure(self): |
686 | - self.assertFailedObserverSetsExtraMessage( |
687 | - _l.UbuntuAppLaunch.AppFailed.START_FAILURE, |
688 | - 'Application failed to start.' |
689 | - ) |
690 | - |
691 | - def test_add_application_cleanups_adds_both_cleanup_actions(self): |
692 | - token = self.getUniqueString() |
693 | - state = { |
694 | - 'status': UpstartApplicationLauncher.Started, |
695 | - 'expected_app_id': token, |
696 | - } |
697 | - launcher = UpstartApplicationLauncher(Mock()) |
698 | - launcher.setUp() |
699 | - launcher._maybe_add_application_cleanups(state) |
700 | - self.assertThat( |
701 | - launcher._cleanups._cleanups, |
702 | - Contains( |
703 | - (launcher._attach_application_log, (token,), {}) |
704 | - ) |
705 | - ) |
706 | - self.assertThat( |
707 | - launcher._cleanups._cleanups, |
708 | - Contains( |
709 | - (launcher._stop_application, (token,), {}) |
710 | - ) |
711 | - ) |
712 | - |
713 | - def test_add_application_cleanups_does_nothing_when_app_timedout(self): |
714 | - state = { |
715 | - 'status': UpstartApplicationLauncher.Timeout, |
716 | - } |
717 | - launcher = UpstartApplicationLauncher(Mock()) |
718 | - launcher.setUp() |
719 | - launcher._maybe_add_application_cleanups(state) |
720 | - self.assertThat(launcher._cleanups._cleanups, HasLength(0)) |
721 | - |
722 | - def test_add_application_cleanups_does_nothing_when_app_failed(self): |
723 | - state = { |
724 | - 'status': UpstartApplicationLauncher.Failed, |
725 | - } |
726 | - launcher = UpstartApplicationLauncher(Mock()) |
727 | - launcher.setUp() |
728 | - launcher._maybe_add_application_cleanups(state) |
729 | - self.assertThat(launcher._cleanups._cleanups, HasLength(0)) |
730 | - |
731 | - def test_attach_application_log_does_nothing_wth_no_log_specified(self): |
732 | - app_id = self.getUniqueString() |
733 | - case_addDetail = Mock() |
734 | - launcher = UpstartApplicationLauncher(case_addDetail) |
735 | - with patch.object(_l.UbuntuAppLaunch, 'application_log_path') as p: |
736 | - p.return_value = None |
737 | - launcher._attach_application_log(app_id) |
738 | - |
739 | - p.assert_called_once_with(app_id) |
740 | - self.assertEqual(0, case_addDetail.call_count) |
741 | - |
742 | - def test_attach_application_log_attaches_log_file(self): |
743 | - token = self.getUniqueString() |
744 | - case_addDetail = Mock() |
745 | - launcher = UpstartApplicationLauncher(case_addDetail) |
746 | - app_id = self.getUniqueString() |
747 | - with tempfile.NamedTemporaryFile(mode='w') as f: |
748 | - f.write(token) |
749 | - f.flush() |
750 | - with patch.object(_l.UbuntuAppLaunch, 'application_log_path', |
751 | - return_value=f.name): |
752 | - launcher._attach_application_log(app_id) |
753 | - |
754 | - self.assertEqual(1, case_addDetail.call_count) |
755 | - content_name, content_obj = case_addDetail.call_args[0] |
756 | - self.assertEqual("Application Log", content_name) |
757 | - self.assertThat(content_obj.as_text(), Contains(token)) |
758 | - |
759 | - def test_stop_adds_app_stopped_observer(self): |
760 | - mock_add_detail = Mock() |
761 | - mock_glib_loop = Mock() |
762 | - patch_get_loop = patch.object( |
763 | - UpstartApplicationLauncher, |
764 | - '_get_glib_loop', |
765 | - new=mock_glib_loop, |
766 | - ) |
767 | - mock_UAL = Mock() |
768 | - patch_UAL = patch.object(_l, 'UbuntuAppLaunch', new=mock_UAL) |
769 | - launcher = UpstartApplicationLauncher(mock_add_detail) |
770 | - app_id = self.getUniqueString() |
771 | - with ExitStack() as patches: |
772 | - patches.enter_context(patch_get_loop) |
773 | - patches.enter_context(patch_UAL) |
774 | - |
775 | - launcher._stop_application(app_id) |
776 | - call_args = mock_UAL.observer_add_app_stop.call_args[0] |
777 | - self.assertThat( |
778 | - call_args[0], |
779 | - Equals(UpstartApplicationLauncher._on_stopped) |
780 | - ) |
781 | - self.assertThat(call_args[1]['expected_app_id'], Equals(app_id)) |
782 | - |
783 | - def test_stop_calls_libUAL_stop_function(self): |
784 | - mock_add_detail = Mock() |
785 | - mock_glib_loop = Mock() |
786 | - patch_get_loop = patch.object( |
787 | - UpstartApplicationLauncher, |
788 | - '_get_glib_loop', |
789 | - new=mock_glib_loop, |
790 | - ) |
791 | - mock_UAL = Mock() |
792 | - patch_UAL = patch.object(_l, 'UbuntuAppLaunch', new=mock_UAL) |
793 | - launcher = UpstartApplicationLauncher(mock_add_detail) |
794 | - app_id = self.getUniqueString() |
795 | - with ExitStack() as patches: |
796 | - patches.enter_context(patch_get_loop) |
797 | - patches.enter_context(patch_UAL) |
798 | - |
799 | - launcher._stop_application(app_id) |
800 | - mock_UAL.stop_application.assert_called_once_with(app_id) |
801 | - |
802 | - def test_stop_logs_error_on_timeout(self): |
803 | - mock_add_detail = Mock() |
804 | - mock_glib_loop = Mock() |
805 | - patch_get_loop = patch.object( |
806 | - UpstartApplicationLauncher, |
807 | - '_get_glib_loop', |
808 | - new=mock_glib_loop, |
809 | - ) |
810 | - mock_UAL = Mock() |
811 | - |
812 | - # we replace the add_observer function with one that can set the |
813 | - # tiemout state, so we can ibject the timeout condition within the |
814 | - # glib loop. This is ugly, but necessary. |
815 | - def fake_add_observer(fn, state): |
816 | - state['status'] = UpstartApplicationLauncher.Timeout |
817 | - mock_UAL.observer_add_app_stop = fake_add_observer |
818 | - patch_UAL = patch.object(_l, 'UbuntuAppLaunch', new=mock_UAL) |
819 | - launcher = UpstartApplicationLauncher(mock_add_detail) |
820 | - app_id = self.getUniqueString() |
821 | - mock_logger = Mock() |
822 | - patch_logger = patch.object(_l, '_logger', new=mock_logger) |
823 | - with ExitStack() as patches: |
824 | - patches.enter_context(patch_get_loop) |
825 | - patches.enter_context(patch_UAL) |
826 | - patches.enter_context(patch_logger) |
827 | - |
828 | - launcher._stop_application(app_id) |
829 | - |
830 | - mock_logger.error.assert_called_once_with( |
831 | - "Timed out waiting for Application with app_id '%s' to stop.", |
832 | - app_id |
833 | - ) |
834 | - |
835 | - |
836 | class ApplicationLauncherInternalTests(TestCase): |
837 | |
838 | def test_get_app_env_from_string_hint_returns_qt_env(self): |
839 | @@ -873,24 +375,6 @@ |
840 | get_application_launcher_wrapper(""), Equals(None) |
841 | ) |
842 | |
843 | - def test_get_click_manifest_returns_python_object(self): |
844 | - example_manifest = """ |
845 | - [{ |
846 | - "description": "Calculator application", |
847 | - "framework": "ubuntu-sdk-13.10", |
848 | - "hooks": { |
849 | - "calculator": { |
850 | - "apparmor": "apparmor/calculator.json", |
851 | - "desktop": "ubuntu-calculator-app.desktop" |
852 | - } |
853 | - }, |
854 | - "icon": "calculator64.png" |
855 | - }] |
856 | - """ |
857 | - with patch.object(_l.subprocess, 'check_output') as check_output: |
858 | - check_output.return_value = example_manifest |
859 | - self.assertThat(_get_click_manifest(), IsInstance(list)) |
860 | - |
861 | @patch.object(_l.psutil, 'pid_exists') |
862 | def test_is_process_running_checks_with_pid(self, pid_exists): |
863 | pid_exists.return_value = True |
864 | |
865 | === modified file 'debian/control' |
866 | --- debian/control 2014-08-06 06:05:02 +0000 |
867 | +++ debian/control 2017-03-03 23:28:24 +0000 |
868 | @@ -10,7 +10,6 @@ |
869 | gir1.2-gconf-2.0, |
870 | gir1.2-gtk-3.0, |
871 | gir1.2-ibus-1.0, |
872 | - gir1.2-ubuntu-app-launch-2, |
873 | graphviz, |
874 | liblttng-ust-dev, |
875 | python-all-dev (>= 2.6), |
876 | @@ -44,7 +43,6 @@ |
877 | Depends: ${misc:Depends}, |
878 | ${python:Depends}, |
879 | python-gi, |
880 | - gir1.2-ubuntu-app-launch-2, |
881 | python-contextlib2, |
882 | python-dbus, |
883 | python-decorator, |
Self-approving because this is necessary for migration.