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
=== modified file 'autopilot/introspection/__init__.py'
--- autopilot/introspection/__init__.py 2013-04-22 01:31:54 +0000
+++ autopilot/introspection/__init__.py 2013-04-22 03:51:26 +0000
@@ -50,11 +50,9 @@
50 # linked executables, which we may need to fix further down the line.50 # linked executables, which we may need to fix further down the line.
51 try:51 try:
52 ldd_output = subprocess.check_output(["ldd", app_path]).strip().lower()52 ldd_output = subprocess.check_output(["ldd", app_path]).strip().lower()
53 except subprocess.CalledProcessError:53 except subprocess.CalledProcessError as e:
54 print "Error: Cannot auto-detect introspection plugin to load."54 raise RuntimeError(e)
55 print "Use the '-i' argument to specify an interface."55 if 'libqtcore' in ldd_output or 'libqt5core' in ldd_output:
56 exit(1) # TODO - don't exit, raise an exception, and handle it appropriately in parent code.
57 if 'libqtcore' in ldd_output:
58 from autopilot.introspection.qt import QtApplicationLauncher56 from autopilot.introspection.qt import QtApplicationLauncher
59 return QtApplicationLauncher()57 return QtApplicationLauncher()
60 elif 'libgtk' in ldd_output:58 elif 'libgtk' in ldd_output:
6159
=== modified file 'autopilot/tests/test_ap_apps.py'
--- autopilot/tests/test_ap_apps.py 2013-04-12 03:53:14 +0000
+++ autopilot/tests/test_ap_apps.py 2013-04-22 03:51:26 +0000
@@ -13,7 +13,6 @@
13from textwrap import dedent13from textwrap import dedent
1414
15from autopilot.testcase import AutopilotTestCase15from autopilot.testcase import AutopilotTestCase
16from autopilot.introspection.gtk import GtkApplicationLauncher
1716
1817
19class ApplicationTests(AutopilotTestCase):18class ApplicationTests(AutopilotTestCase):
@@ -97,6 +96,11 @@
97 except subprocess.CalledProcessError:96 except subprocess.CalledProcessError:
98 self.skip("gnome-mahjongg not found.")97 self.skip("gnome-mahjongg not found.")
9998
99 def pick_app_launcher(self, app_path):
100 # force Gtk app introspection:
101 from autopilot.introspection.gtk import GtkApplicationLauncher
102 return GtkApplicationLauncher()
103
100 def test_can_launch_gtk_app(self):104 def test_can_launch_gtk_app(self):
101 app_proxy = self.launch_test_application(self.app_path)105 app_proxy = self.launch_test_application(self.app_path)
102 self.assertTrue(app_proxy is not None)106 self.assertTrue(app_proxy is not None)
103107
=== modified file 'autopilot/tests/test_autopilot_functional.py'
--- autopilot/tests/test_autopilot_functional.py 2013-02-21 02:44:18 +0000
+++ autopilot/tests/test_autopilot_functional.py 2013-04-22 03:51:26 +0000
@@ -594,7 +594,7 @@
594594
595 self.assertThat(rc, Equals(1))595 self.assertThat(rc, Equals(1))
596 self.assertThat(stdout,596 self.assertThat(stdout,
597 Contains("Error: Cannot auto-detect introspection plugin to load.\nUse the '-i' argument to specify an interface."))597 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"))
598598
599599
600class AutopilotVerboseFunctionalTests(AutopilotFunctionalTestsBase):600class AutopilotVerboseFunctionalTests(AutopilotFunctionalTestsBase):
601601
=== modified file 'bin/autopilot'
--- bin/autopilot 2013-04-12 03:53:14 +0000
+++ bin/autopilot 2013-04-22 03:51:26 +0000
@@ -27,7 +27,7 @@
27from argparse import ArgumentParser27from argparse import ArgumentParser
28from unittest.loader import TestLoader28from unittest.loader import TestLoader
29from unittest import TestSuite29from unittest import TestSuite
30from autopilot.introspection import launch_application30from autopilot.introspection import launch_application, get_application_launcher
31from autopilot.introspection.gtk import GtkApplicationLauncher31from autopilot.introspection.gtk import GtkApplicationLauncher
32from autopilot.introspection.qt import QtApplicationLauncher32from autopilot.introspection.qt import QtApplicationLauncher
3333
@@ -347,13 +347,19 @@
347 # We now have a full path to the application.347 # We now have a full path to the application.
348 launcher = None348 launcher = None
349 if args.interface == 'Auto':349 if args.interface == 'Auto':
350 launcher = get_application_introspection_base(app_name)350 try:
351 launcher = get_application_launcher(app_name)
352 except RuntimeError as e:
353 print "Error detecting launcher: %s" % e.message
354 print "(Perhaps use the '-i' argument to specify an interface.)"
355 exit(1)
351 elif args.interface == 'Gtk':356 elif args.interface == 'Gtk':
352 launcher = GtkApplicationLauncher()357 launcher = GtkApplicationLauncher()
353 elif args.interface == 'Qt':358 elif args.interface == 'Qt':
354 launcher = QtApplicationLauncher()359 launcher = QtApplicationLauncher()
355 if launcher is None:360 if launcher is None:
356 print "Error: Could not determine introspection type to use for application '%s'." % app_name361 print "Error: Could not determine introspection type to use for application '%s'." % app_name
362 print "(Perhaps use the '-i' argument to specify an interface.)"
357 exit(1)363 exit(1)
358364
359 try:365 try:
@@ -363,28 +369,6 @@
363 exit(1)369 exit(1)
364370
365371
366def get_application_introspection_base(app_path):
367 """Return a base class that knows how to enable introspection for this app,
368 or None.
369
370 """
371 # TODO: this is a teeny bit hacky - we call ldd to check whether this application
372 # links to certain library. We're assuming that linking to libQt* or libGtk*
373 # means the application is introspectable. This excludes any non-dynamically
374 # linked executables, which we may need to fix further down the line.
375 try:
376 ldd_output = subprocess.check_output(["ldd", app_path]).strip().lower()
377 except subprocess.CalledProcessError:
378 print "Error: Cannot auto-detect introspection plugin to load."
379 print "Use the '-i' argument to specify an interface."
380 exit(1)
381 if 'libqtcore' in ldd_output:
382 return QtApplicationLauncher
383 elif 'libgtk' in ldd_output:
384 return GtkApplicationLauncher
385 return None
386
387
388def run_vis(args):372def run_vis(args):
389 setup_logging(args.verbose)373 setup_logging(args.verbose)
390 # importing this requires that DISPLAY is set. Since we don't always want374 # importing this requires that DISPLAY is set. Since we don't always want

Subscribers

People subscribed via source and target branches