Merge lp:~veebers/autopilot/application_launcher_exception_not_exit into lp:autopilot

Proposed by Christopher Lee
Status: Merged
Approved by: Thomi Richards
Approved revision: 169
Merged at revision: 166
Proposed branch: lp:~veebers/autopilot/application_launcher_exception_not_exit
Merge into: lp:autopilot
Diff against target: 118 lines (+17/-31)
4 files modified
autopilot/introspection/__init__.py (+3/-5)
autopilot/tests/test_ap_apps.py (+5/-1)
autopilot/tests/test_autopilot_functional.py (+1/-1)
bin/autopilot (+8/-24)
To merge this branch: bzr merge lp:~veebers/autopilot/application_launcher_exception_not_exit
Reviewer Review Type Date Requested Status
Thomi Richards (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+159999@code.launchpad.net

Commit message

autopilot.introspection get_application_launcher potentially calls exit(1) if it fails to detect the application launcher.
This shouldn't exit but do something else (probably raise an exception?).

Description of the change

Change autopilot.introspection get_application_launcher so that it doesn't exit(1) but throws an exception instead.

To post a comment you must log in.
169. By Christopher Lee

Update tests

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'autopilot/introspection/__init__.py'
2--- autopilot/introspection/__init__.py 2013-04-22 01:31:54 +0000
3+++ autopilot/introspection/__init__.py 2013-04-22 03:51:26 +0000
4@@ -50,11 +50,9 @@
5 # linked executables, which we may need to fix further down the line.
6 try:
7 ldd_output = subprocess.check_output(["ldd", app_path]).strip().lower()
8- except subprocess.CalledProcessError:
9- print "Error: Cannot auto-detect introspection plugin to load."
10- print "Use the '-i' argument to specify an interface."
11- exit(1) # TODO - don't exit, raise an exception, and handle it appropriately in parent code.
12- if 'libqtcore' in ldd_output:
13+ except subprocess.CalledProcessError as e:
14+ raise RuntimeError(e)
15+ if 'libqtcore' in ldd_output or 'libqt5core' in ldd_output:
16 from autopilot.introspection.qt import QtApplicationLauncher
17 return QtApplicationLauncher()
18 elif 'libgtk' in ldd_output:
19
20=== modified file 'autopilot/tests/test_ap_apps.py'
21--- autopilot/tests/test_ap_apps.py 2013-04-12 03:53:14 +0000
22+++ autopilot/tests/test_ap_apps.py 2013-04-22 03:51:26 +0000
23@@ -13,7 +13,6 @@
24 from textwrap import dedent
25
26 from autopilot.testcase import AutopilotTestCase
27-from autopilot.introspection.gtk import GtkApplicationLauncher
28
29
30 class ApplicationTests(AutopilotTestCase):
31@@ -97,6 +96,11 @@
32 except subprocess.CalledProcessError:
33 self.skip("gnome-mahjongg not found.")
34
35+ def pick_app_launcher(self, app_path):
36+ # force Gtk app introspection:
37+ from autopilot.introspection.gtk import GtkApplicationLauncher
38+ return GtkApplicationLauncher()
39+
40 def test_can_launch_gtk_app(self):
41 app_proxy = self.launch_test_application(self.app_path)
42 self.assertTrue(app_proxy is not None)
43
44=== modified file 'autopilot/tests/test_autopilot_functional.py'
45--- autopilot/tests/test_autopilot_functional.py 2013-02-21 02:44:18 +0000
46+++ autopilot/tests/test_autopilot_functional.py 2013-04-22 03:51:26 +0000
47@@ -594,7 +594,7 @@
48
49 self.assertThat(rc, Equals(1))
50 self.assertThat(stdout,
51- Contains("Error: Cannot auto-detect introspection plugin to load.\nUse the '-i' argument to specify an interface."))
52+ Contains("Error detecting launcher: Command '['ldd', '/usr/bin/tzselect']' returned non-zero exit status 1\n(Perhaps use the '-i' argument to specify an interface.)\n"))
53
54
55 class AutopilotVerboseFunctionalTests(AutopilotFunctionalTestsBase):
56
57=== modified file 'bin/autopilot'
58--- bin/autopilot 2013-04-12 03:53:14 +0000
59+++ bin/autopilot 2013-04-22 03:51:26 +0000
60@@ -27,7 +27,7 @@
61 from argparse import ArgumentParser
62 from unittest.loader import TestLoader
63 from unittest import TestSuite
64-from autopilot.introspection import launch_application
65+from autopilot.introspection import launch_application, get_application_launcher
66 from autopilot.introspection.gtk import GtkApplicationLauncher
67 from autopilot.introspection.qt import QtApplicationLauncher
68
69@@ -347,13 +347,19 @@
70 # We now have a full path to the application.
71 launcher = None
72 if args.interface == 'Auto':
73- launcher = get_application_introspection_base(app_name)
74+ try:
75+ launcher = get_application_launcher(app_name)
76+ except RuntimeError as e:
77+ print "Error detecting launcher: %s" % e.message
78+ print "(Perhaps use the '-i' argument to specify an interface.)"
79+ exit(1)
80 elif args.interface == 'Gtk':
81 launcher = GtkApplicationLauncher()
82 elif args.interface == 'Qt':
83 launcher = QtApplicationLauncher()
84 if launcher is None:
85 print "Error: Could not determine introspection type to use for application '%s'." % app_name
86+ print "(Perhaps use the '-i' argument to specify an interface.)"
87 exit(1)
88
89 try:
90@@ -363,28 +369,6 @@
91 exit(1)
92
93
94-def get_application_introspection_base(app_path):
95- """Return a base class that knows how to enable introspection for this app,
96- or None.
97-
98- """
99- # TODO: this is a teeny bit hacky - we call ldd to check whether this application
100- # links to certain library. We're assuming that linking to libQt* or libGtk*
101- # means the application is introspectable. This excludes any non-dynamically
102- # linked executables, which we may need to fix further down the line.
103- try:
104- ldd_output = subprocess.check_output(["ldd", app_path]).strip().lower()
105- except subprocess.CalledProcessError:
106- print "Error: Cannot auto-detect introspection plugin to load."
107- print "Use the '-i' argument to specify an interface."
108- exit(1)
109- if 'libqtcore' in ldd_output:
110- return QtApplicationLauncher
111- elif 'libgtk' in ldd_output:
112- return GtkApplicationLauncher
113- return None
114-
115-
116 def run_vis(args):
117 setup_logging(args.verbose)
118 # importing this requires that DISPLAY is set. Since we don't always want

Subscribers

People subscribed via source and target branches