Merge lp:~thomir-deactivatedaccount/autopilot/fix-for-1172914 into lp:autopilot

Proposed by Thomi Richards
Status: Merged
Approved by: Christopher Lee
Approved revision: 174
Merged at revision: 172
Proposed branch: lp:~thomir-deactivatedaccount/autopilot/fix-for-1172914
Merge into: lp:autopilot
Diff against target: 224 lines (+59/-34)
4 files modified
autopilot/introspection/__init__.py (+14/-1)
autopilot/testcase.py (+36/-11)
autopilot/tests/test_ap_apps.py (+5/-15)
bin/autopilot (+4/-7)
To merge this branch: bzr merge lp:~thomir-deactivatedaccount/autopilot/fix-for-1172914
Reviewer Review Type Date Requested Status
Christopher Lee (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+161040@code.launchpad.net

Commit message

Make it easier to specify an introspection type.

Description of the change

Make it easier to specify an introspection type.

To post a comment you must log in.
174. By Thomi Richards

whitespace fix.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Christopher Lee (veebers) wrote :

Looks good to me.

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-23 21:07:58 +0000
3+++ autopilot/introspection/__init__.py 2013-04-25 23:06:25 +0000
4@@ -72,6 +72,19 @@
5 return None
6
7
8+def get_application_launcher_from_string_hint(hint):
9+ """Return in instance of :class:`ApplicationLauncher` given a string hint."""
10+ from autopilot.introspection.qt import QtApplicationLauncher
11+ from autopilot.introspection.gtk import GtkApplicationLauncher
12+
13+ hint = hint.lower()
14+ if hint == 'qt':
15+ return QtApplicationLauncher()
16+ elif hint == 'gtk':
17+ return GtkApplicationLauncher()
18+ return None
19+
20+
21 def launch_application(launcher, application, *arguments, **kwargs):
22 """Launch an application, and return a process object.
23
24@@ -117,7 +130,7 @@
25
26
27 def launch_process(application, args, capture_output, **kwargs):
28- """Launch an autopilot-enabled process and return the proxy object."""
29+ """Launch an autopilot-enabled process and return the process object."""
30 commandline = [application]
31 commandline.extend(args)
32 logger.info("Launching process: %r", commandline)
33
34=== modified file 'autopilot/testcase.py'
35--- autopilot/testcase.py 2013-04-23 21:07:58 +0000
36+++ autopilot/testcase.py 2013-04-25 23:06:25 +0000
37@@ -22,8 +22,6 @@
38
39 from __future__ import absolute_import
40
41-from dbus import DBusException
42-from gi.repository import Gio
43 import logging
44 import os
45 import signal
46@@ -39,9 +37,9 @@
47 from autopilot.input import Keyboard, Mouse
48 from autopilot.introspection import (
49 get_application_launcher,
50+ get_application_launcher_from_string_hint,
51 get_autopilot_proxy_object_for_process,
52 launch_application,
53- launch_process,
54 )
55 from autopilot.display import Display
56 from autopilot.globals import on_test_started
57@@ -237,19 +235,37 @@
58 is launched.
59
60 This method is designed to be flexible enough to launch all supported
61- types of applications. For example, to launch a traditional Gtk application,
62- a test might start with::
63+ types of applications. Autopilot can automatically determine how to enable
64+ introspection support for dynamically linked binary applications. For
65+ example, to launch a binary Gtk application, a test might start with::
66
67 app_proxy = self.launch_test_application('gedit')
68
69- ... a Qt4 Qml application might be launched like this::
70+ Applications can be given command line arguments by supplying positional
71+ arguments to this method. For example, if we want to launch ``gedit``
72+ with a certain document loaded, we might do this::
73
74- app_proxy = self.launch_test_application('qmlviewer', 'my_scene.qml')
75+ app_proxy = self.launch_test_application('gedit', '/tmp/test-document.txt')
76
77 ... a Qt5 Qml application is launched in a similar fashion::
78
79 app_proxy = self.launch_test_application('qmlscene', 'my_scene.qml')
80
81+ If you wish to launch an application that is not a dynamically linked
82+ binary, you must specify the application type. For example, a Qt4 python
83+ application might be launched like this::
84+
85+ app_proxy = self.launch_test_application('my_qt_app.py', app_type='qt')
86+
87+ Similarly, a python/Gtk application is launched like so::
88+
89+ app_proxy = self.launch_test_application('my_gtk_app.py', app_type='gtk')
90+
91+ .. seealso::
92+
93+ Method :py:meth:`AutopilotTestCase.pick_app_launcher`
94+ Specify application introspection type globally.
95+
96 :param application: The application to launch. The application can be
97 specified as:
98
99@@ -257,6 +273,11 @@
100 * A relative path to an executable file. (``./build/my_app``)
101 * An app name, which will be searched for in $PATH (``my_app``)
102
103+ :keyword app_type: If set, provides a hint to autopilot as to which kind
104+ of introspection to enable. This is needed when the application you
105+ wish to launch is *not* a dynamically linked binary. Valid values are
106+ 'gtk' or 'qt'. These strings are case insensitive.
107+
108 :keyword launch_dir: If set to a directory that exists the process will be
109 launched from that directory.
110
111@@ -270,11 +291,15 @@
112 """
113 app_path = subprocess.check_output(['which',application]).strip()
114 # Get a launcher, tests can override this if they need:
115+ launcher_hint = kwargs.pop('app_type', '')
116 launcher = None
117- try:
118- launcher = self.pick_app_launcher(app_path)
119- except RuntimeError:
120- pass
121+ if launcher_hint != '':
122+ launcher = get_application_launcher_from_string_hint(launcher_hint)
123+ if launcher is None:
124+ try:
125+ launcher = self.pick_app_launcher(app_path)
126+ except RuntimeError:
127+ pass
128 if launcher is None:
129 raise RuntimeError("Autopilot could not determine the correct \
130 introspection type to use. You can specify one by overriding the \
131
132=== modified file 'autopilot/tests/test_ap_apps.py'
133--- autopilot/tests/test_ap_apps.py 2013-04-23 21:07:58 +0000
134+++ autopilot/tests/test_ap_apps.py 2013-04-25 23:06:25 +0000
135@@ -70,13 +70,8 @@
136 except subprocess.CalledProcessError:
137 self.skip("qmlscene not found.")
138
139- def pick_app_launcher(self, app_path):
140- # force Qt app introspection:
141- from autopilot.introspection.qt import QtApplicationLauncher
142- return QtApplicationLauncher()
143-
144 def test_can_launch_qt_app(self):
145- app_proxy = self.launch_test_application(self.app_path)
146+ app_proxy = self.launch_test_application(self.app_path, app_type='qt')
147 self.assertTrue(app_proxy is not None)
148
149 def test_can_launch_qt_script(self):
150@@ -90,7 +85,7 @@
151 win.show()
152 app.exec_()
153 """))
154- app_proxy = self.launch_test_application(path)
155+ app_proxy = self.launch_test_application(path, app_type='qt')
156 self.assertTrue(app_proxy is not None)
157
158 def test_can_launch_wrapper_script(self):
159@@ -111,7 +106,7 @@
160 %s $*
161 """ % (path, path)),
162 extension=".sh")
163- app_proxy = self.launch_test_application(wrapper_path)
164+ app_proxy = self.launch_test_application(wrapper_path, app_type='qt')
165 self.assertTrue(app_proxy is not None)
166
167
168@@ -125,11 +120,6 @@
169 except subprocess.CalledProcessError:
170 self.skip("gnome-mahjongg not found.")
171
172- def pick_app_launcher(self, app_path):
173- # force Gtk app introspection:
174- from autopilot.introspection.gtk import GtkApplicationLauncher
175- return GtkApplicationLauncher()
176-
177 def test_can_launch_gtk_app(self):
178 app_proxy = self.launch_test_application(self.app_path)
179 self.assertTrue(app_proxy is not None)
180@@ -144,7 +134,7 @@
181 win.show_all()
182 Gtk.main()
183 """))
184- app_proxy = self.launch_test_application(path)
185+ app_proxy = self.launch_test_application(path, app_type='gtk')
186 self.assertTrue(app_proxy is not None)
187
188 def test_can_launch_wrapper_script(self):
189@@ -164,5 +154,5 @@
190 %s
191 """ % (path, path)),
192 extension=".sh")
193- app_proxy = self.launch_test_application(wrapper_path)
194+ app_proxy = self.launch_test_application(wrapper_path, app_type='gtk')
195 self.assertTrue(app_proxy is not None)
196
197=== modified file 'bin/autopilot'
198--- bin/autopilot 2013-04-23 21:07:58 +0000
199+++ bin/autopilot 2013-04-25 23:06:25 +0000
200@@ -351,7 +351,8 @@
201
202 def launch_app(args):
203 """Launch an application, with introspection support."""
204- from autopilot.introspection import launch_application, get_application_launcher
205+ from autopilot.introspection import launch_application, get_application_launcher, get_application_launcher_from_string_hint
206+
207 setup_logging(args.verbose)
208 app_name = args.application[0]
209 if not isabs(app_name) or not exists(app_name):
210@@ -370,12 +371,8 @@
211 print "Error detecting launcher: %s" % e.message
212 print "(Perhaps use the '-i' argument to specify an interface.)"
213 exit(1)
214- elif args.interface == 'Gtk':
215- from autopilot.introspection.gtk import GtkApplicationLauncher
216- launcher = GtkApplicationLauncher()
217- elif args.interface == 'Qt':
218- from autopilot.introspection.qt import QtApplicationLauncher
219- launcher = QtApplicationLauncher()
220+ else:
221+ launcher = get_application_launcher_from_string_hint(args.interface)
222 if launcher is None:
223 print "Error: Could not determine introspection type to use for application '%s'." % app_name
224 print "(Perhaps use the '-i' argument to specify an interface.)"

Subscribers

People subscribed via source and target branches