Merge lp:~thomir-deactivatedaccount/autopilot/fix-pick-variant into lp:autopilot

Proposed by Thomi Richards
Status: Merged
Approved by: Christopher Lee
Approved revision: 160
Merged at revision: 159
Proposed branch: lp:~thomir-deactivatedaccount/autopilot/fix-pick-variant
Merge into: lp:autopilot
Diff against target: 422 lines (+173/-65)
18 files modified
autopilot/__init__.py (+14/-4)
autopilot/display/__init__.py (+17/-7)
autopilot/input/__init__.py (+51/-19)
autopilot/process/__init__.py (+15/-5)
autopilot/tests/test_custom_exceptions.py (+31/-0)
autopilot/utilities.py (+9/-2)
docs/_templates/indexcontent.html (+1/-1)
docs/api/autopilot.rst (+8/-10)
docs/api/display.rst (+2/-2)
docs/api/emulators.rst (+2/-2)
docs/api/gestures.rst (+2/-2)
docs/api/index.rst (+10/-0)
docs/api/input.rst (+2/-2)
docs/api/introspection.rst (+2/-2)
docs/api/matchers.rst (+2/-2)
docs/api/platform.rst (+2/-2)
docs/api/testcase.rst (+2/-2)
docs/conf.py (+1/-1)
To merge this branch: bzr merge lp:~thomir-deactivatedaccount/autopilot/fix-pick-variant
Reviewer Review Type Date Requested Status
Christopher Lee (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+159074@code.launchpad.net

Commit message

_pick_variant now raises an exception when requested backend was not available.

Description of the change

When asking for a specific stack backend, we now either return the requested backend, or raise an exception. This had a number of knock-on changes, including:
 * A new exception in the autopilot module.
 * Changes to the documentation in the input, process, and display packages.
 * A few other documentation changes.

There are extra tests around the BackendException class.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
160. By Thomi Richards

fixed typo, and re-introduced the version string.

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

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'autopilot/__init__.py'
2--- autopilot/__init__.py 2012-05-07 17:38:00 +0000
3+++ autopilot/__init__.py 2013-04-16 05:01:27 +0000
4@@ -6,7 +6,17 @@
5 # under the terms of the GNU General Public License version 3, as published
6 # by the Free Software Foundation.
7
8-"""An automated test runner and driver for Unity"""
9-
10-
11-version = "1.0"
12+
13+version = '1.3'
14+
15+
16+class BackendException(RuntimeError):
17+
18+ """An error occured while trying to initialise an autopilot backend."""
19+
20+ def __init__(self, original_exception):
21+ super(BackendException, self).__init__(
22+ "Error while initialising backend. Original exception was: " \
23+ + original_exception.message
24+ )
25+ self.original_exception = original_exception
26
27=== modified file 'autopilot/display/__init__.py'
28--- autopilot/display/__init__.py 2013-04-08 03:46:47 +0000
29+++ autopilot/display/__init__.py 2013-04-16 05:01:27 +0000
30@@ -90,13 +90,23 @@
31 def create(preferred_variant=''):
32 """Get an instance of the Display class.
33
34- If variant is specified, it should be a string that specifies a backend to
35- use. However, this hint can be ignored - autopilot will prefer to return a
36- variant other than the one requested, rather than fail to return anything at
37- all.
38-
39- If autopilot cannot instantate any of the possible backends, a RuntimeError
40- will be raised.
41+ :param preferred_variant: A string containing a hint as to which variant you
42+ would like. If left blank, autopilot will pick a suitable
43+ variant for you. Specifying a variant will guarantee that either that
44+ variant is returned, or an exception is raised.
45+
46+ possible variants are:
47+
48+ * ``X11`` - Get display information from X11.
49+ * ``UPA`` - Get display information from the ubuntu platform API.
50+
51+ :raises: RuntimeError if autopilot cannot instantate any of the possible
52+ backends.
53+ :raises: RuntimeError if the preferred_variant is specified and is not
54+ one of the possible backends for this device class.
55+ :raises: :class:`~autopilot.BackendException` if the preferred_variant is
56+ set, but that variant could not be instantiated.
57+
58 """
59 def get_x11_display():
60 from autopilot.display._X11 import Display
61
62=== modified file 'autopilot/input/__init__.py'
63--- autopilot/input/__init__.py 2013-04-08 03:46:47 +0000
64+++ autopilot/input/__init__.py 2013-04-16 05:01:27 +0000
65@@ -17,9 +17,11 @@
66 events (possibly UInput).
67
68 Test authors should instantiate the appropriate class using the ``create`` method
69-on each class. Tests can provide a hint to this method to suggest that a particular
70-subsystem be used. However, autopilot will prefer to return a subsystem other than
71-the one specified, if the requested subsystem is unavailable.
72+on each class. Calling ``create()`` with no arguments will get an instance of the
73+specified class that suits the current platform. In this case, autopilot will
74+do it's best to pick a suitable variant. Calling ``create`` with a variant name
75+will result in that specific variant type being returned, or, if it cannot be created,
76+an exception will be raised. The exception type varies from variant to variant.
77
78 There are three basic input types available:
79
80@@ -49,12 +51,23 @@
81 def create(preferred_variant=''):
82 """Get an instance of the :py:class:`Keyboard` class.
83
84- :param preferred_variant: A string containing a hint as to which variant you
85- would like. However, this hint can be ignored - autopilot will prefer to
86- return a keyboard variant other than the one requested, rather than fail
87- to return anything at all.
88- :raises: a RuntimeError will be raised if autopilot cannot instantate any of
89- the possible backends.
90+ :param preferred_variant: A string containing a hint as to which variant
91+ you would like. If left blank, autopilot will pick a suitable
92+ variant for you. Specifying a variant will guarantee that either that
93+ variant is returned, or an exception is raised.
94+
95+ possible variants are:
96+
97+ * ``X11`` - Generate keyboard events using the X11 client libraries.
98+ * ``UInput`` - Use UInput kernel-level device driver.
99+
100+ :raises: RuntimeError if autopilot cannot instantate any of the possible
101+ backends.
102+ :raises: RuntimeError if the preferred_variant is specified and is not
103+ one of the possible backends for this device class.
104+ :raises: :class:`~autopilot.BackendException` if the preferred_variant is
105+ set, but that variant could not be instantiated.
106+
107
108 """
109 def get_x11_kb():
110@@ -167,11 +180,20 @@
111 """Get an instance of the :py:class:`Mouse` class.
112
113 :param preferred_variant: A string containing a hint as to which variant you
114- would like. However, this hint can be ignored - autopilot will prefer to
115- return a mouse variant other than the one requested, rather than fail
116- to return anything at all.
117- :raises: a RuntimeError will be raised if autopilot cannot instantate any of
118- the possible backends.
119+ would like. If left blank, autopilot will pick a suitable
120+ variant for you. Specifying a variant will guarantee that either that
121+ variant is returned, or an exception is raised.
122+
123+ possible variants are:
124+
125+ * ``X11`` - Generate mouse events using the X11 client libraries.
126+
127+ :raises: RuntimeError if autopilot cannot instantate any of the possible
128+ backends.
129+ :raises: RuntimeError if the preferred_variant is specified and is not
130+ one of the possible backends for this device class.
131+ :raises: :class:`~autopilot.BackendException` if the preferred_variant is
132+ set, but that variant could not be instantiated.
133
134 """
135 def get_x11_mouse():
136@@ -262,11 +284,21 @@
137 """Get an instance of the :py:class:`Touch` class.
138
139 :param preferred_variant: A string containing a hint as to which variant you
140- would like. However, this hint can be ignored - autopilot will prefer to
141- return a touch variant other than the one requested, rather than fail
142- to return anything at all.
143- :raises: a RuntimeError will be raised if autopilot cannot instantate any of
144- the possible backends.
145+ would like. If left blank, autopilot will pick a suitable
146+ variant for you. Specifying a variant will guarantee that either that
147+ variant is returned, or an exception is raised.
148+
149+ possible variants are:
150+
151+ * ``UInput`` - Use UInput kernel-level device driver.
152+
153+ :raises: RuntimeError if autopilot cannot instantate any of the possible
154+ backends.
155+ :raises: RuntimeError if the preferred_variant is specified and is not
156+ one of the possible backends for this device class.
157+ :raises: :class:`~autopilot.BackendException` if the preferred_variant is
158+ set, but that variant could not be instantiated.
159+
160
161 """
162 def get_uinput_touch():
163
164=== modified file 'autopilot/process/__init__.py'
165--- autopilot/process/__init__.py 2013-04-15 03:39:09 +0000
166+++ autopilot/process/__init__.py 2013-04-16 05:01:27 +0000
167@@ -58,11 +58,21 @@
168 """Get an instance of the :py:class:`ProcessManager` class.
169
170 :param preferred_variant: A string containing a hint as to which variant you
171- would like. However, this hint can be ignored - autopilot will prefer to
172- return a keyboard variant other than the one requested, rather than fail
173- to return anything at all.
174- :raises: a RuntimeError will be raised if autopilot cannot instantate any of
175- the possible backends.
176+ would like. If left blank, autopilot will pick a suitable
177+ variant for you. Specifying a variant will guarantee that either that
178+ variant is returned, or an exception is raised.
179+
180+ possible variants are:
181+
182+ * ``BAMF`` - Get process information using the BAMF Application Matching Framework.
183+
184+ :raises: RuntimeError if autopilot cannot instantate any of the possible
185+ backends.
186+ :raises: RuntimeError if the preferred_variant is specified and is not
187+ one of the possible backends for this device class.
188+ :raises: :class:`~autopilot.BackendException` if the preferred_variant is
189+ set, but that variant could not be instantiated.
190+
191 """
192 def get_bamf_pm():
193 from autopilot.process._bamf import ProcessManager
194
195=== added file 'autopilot/tests/test_custom_exceptions.py'
196--- autopilot/tests/test_custom_exceptions.py 1970-01-01 00:00:00 +0000
197+++ autopilot/tests/test_custom_exceptions.py 2013-04-16 05:01:27 +0000
198@@ -0,0 +1,31 @@
199+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
200+# Copyright 2013 Canonical
201+# Author: Thomi Richards
202+#
203+# This program is free software: you can redistribute it and/or modify it
204+# under the terms of the GNU General Public License version 3, as published
205+# by the Free Software Foundation.
206+
207+
208+from testtools import TestCase
209+from testtools.matchers import Equals, IsInstance
210+
211+from autopilot import BackendException
212+
213+class BackendExceptionTests(TestCase):
214+
215+ def test_must_wrap_exception(self):
216+ """BackendException must be able to wrap another exception instance."""
217+ err = BackendException(RuntimeError("Hello World"))
218+ self.assertThat(err.original_exception, IsInstance(RuntimeError))
219+ self.assertThat(err.original_exception.message, Equals("Hello World"))
220+
221+ def test_dunder_str(self):
222+ err = BackendException(RuntimeError("Hello World"))
223+ self.assertThat(str(err),
224+ Equals("Error while initialising backend. Original exception was: Hello World"))
225+
226+ def test_dunder_repr(self):
227+ err = BackendException(RuntimeError("Hello World"))
228+ self.assertThat(repr(err),
229+ Equals("BackendException('Error while initialising backend. Original exception was: Hello World',)"))
230
231=== modified file 'autopilot/utilities.py'
232--- autopilot/utilities.py 2013-04-08 01:05:45 +0000
233+++ autopilot/utilities.py 2013-04-16 05:01:27 +0000
234@@ -20,12 +20,17 @@
235 import time
236 from functools import wraps
237
238+from autopilot import BackendException
239+
240
241 def _pick_variant(variants, preferred_variant):
242 possible_backends = variants.keys()
243 get_debug_logger().debug("Possible variants: %s", ','.join(possible_backends))
244- if preferred_variant in possible_backends:
245- possible_backends.sort(lambda a,b: -1 if a == preferred_variant else 0)
246+ if preferred_variant:
247+ if preferred_variant in possible_backends:
248+ possible_backends.sort(lambda a,b: -1 if a == preferred_variant else 0)
249+ else:
250+ raise RuntimeError("Unknown backend '%s'" % (preferred_variant))
251 failure_reasons = []
252 for be in possible_backends:
253 try:
254@@ -33,6 +38,8 @@
255 except Exception as e:
256 get_debug_logger().warning("Can't create variant %s: %r", be, e)
257 failure_reasons.append('%s: %r' % (be, e))
258+ if preferred_variant != '':
259+ raise BackendException(e)
260 raise RuntimeError("Unable to instantiate any backends\n%s" % '\n'.join(failure_reasons))
261
262
263
264=== modified file 'docs/_templates/indexcontent.html'
265--- docs/_templates/indexcontent.html 2013-04-15 03:33:21 +0000
266+++ docs/_templates/indexcontent.html 2013-04-16 05:01:27 +0000
267@@ -12,7 +12,7 @@
268 </td>
269 <td width="50%">
270 <p class="biglink">
271- <a class="biglink" href="{{ pathto("api/autopilot") }}">API Reference</a><br/>
272+ <a class="biglink" href="{{ pathto("api/index") }}">API Reference</a><br/>
273 <span class="linkdescr">API reference documentation for Autopilot.</span>
274 </p>
275 </td>
276
277=== modified file 'docs/api/autopilot.rst'
278--- docs/api/autopilot.rst 2013-04-14 21:56:27 +0000
279+++ docs/api/autopilot.rst 2013-04-16 05:01:27 +0000
280@@ -1,10 +1,8 @@
281-:orphan:
282-
283-Autopilot API Documentation
284-===========================
285-
286-.. toctree::
287- :maxdepth: 1
288- :glob:
289-
290- *
291+``autopilot`` - Global stuff
292+++++++++++++++++++++++++++++
293+
294+
295+.. automodule:: autopilot
296+ :members:
297+ :undoc-members:
298+
299
300=== modified file 'docs/api/display.rst'
301--- docs/api/display.rst 2013-04-05 05:26:23 +0000
302+++ docs/api/display.rst 2013-04-16 05:01:27 +0000
303@@ -1,5 +1,5 @@
304-``display`` - Get information about the current display(s)
305-++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
306+``autopilot.display`` - Get information about the current display(s)
307+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
308
309
310 .. automodule:: autopilot.display
311
312=== modified file 'docs/api/emulators.rst'
313--- docs/api/emulators.rst 2013-04-15 01:15:52 +0000
314+++ docs/api/emulators.rst 2013-04-16 05:01:27 +0000
315@@ -1,5 +1,5 @@
316-``emulators`` - Backwards compatibility for autopilot v1.2
317-++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
318+``autopilot.emulators`` - Backwards compatibility for autopilot v1.2
319+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
320
321
322 .. module autopilot.emulators
323
324=== modified file 'docs/api/gestures.rst'
325--- docs/api/gestures.rst 2013-04-05 04:57:25 +0000
326+++ docs/api/gestures.rst 2013-04-16 05:01:27 +0000
327@@ -1,5 +1,5 @@
328-``gestures`` - Gestural and multi-touch support
329-+++++++++++++++++++++++++++++++++++++++++++++++
330+``autopilot.gestures`` - Gestural and multi-touch support
331++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
332
333
334 .. automodule:: autopilot.gestures
335
336=== added file 'docs/api/index.rst'
337--- docs/api/index.rst 1970-01-01 00:00:00 +0000
338+++ docs/api/index.rst 2013-04-16 05:01:27 +0000
339@@ -0,0 +1,10 @@
340+:orphan:
341+
342+Autopilot API Documentation
343+===========================
344+
345+.. toctree::
346+ :maxdepth: 1
347+ :glob:
348+
349+ *
350
351=== modified file 'docs/api/input.rst'
352--- docs/api/input.rst 2013-04-05 05:26:23 +0000
353+++ docs/api/input.rst 2013-04-16 05:01:27 +0000
354@@ -1,5 +1,5 @@
355-``input`` - Generate keyboard, mouse, and touch input events
356-++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
357+``autopilot.input`` - Generate keyboard, mouse, and touch input events
358+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
359
360
361 .. automodule:: autopilot.input
362
363=== modified file 'docs/api/introspection.rst'
364--- docs/api/introspection.rst 2013-04-15 01:00:21 +0000
365+++ docs/api/introspection.rst 2013-04-16 05:01:27 +0000
366@@ -1,5 +1,5 @@
367-``introspection`` - Autopilot introspection internals
368-+++++++++++++++++++++++++++++++++++++++++++++++++++++
369+``autopilot.introspection`` - Autopilot introspection internals
370++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
371
372
373 .. automodule:: autopilot.introspection
374
375=== modified file 'docs/api/matchers.rst'
376--- docs/api/matchers.rst 2013-04-05 04:15:17 +0000
377+++ docs/api/matchers.rst 2013-04-16 05:01:27 +0000
378@@ -1,5 +1,5 @@
379-``matchers`` - Custom matchers for test assertions
380-++++++++++++++++++++++++++++++++++++++++++++++++++
381+``autopilot.matchers`` - Custom matchers for test assertions
382+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
383
384
385 .. automodule:: autopilot.matchers
386
387=== modified file 'docs/api/platform.rst'
388--- docs/api/platform.rst 2013-04-05 04:15:17 +0000
389+++ docs/api/platform.rst 2013-04-16 05:01:27 +0000
390@@ -1,5 +1,5 @@
391-``Platform`` - Functions for platform detection
392-+++++++++++++++++++++++++++++++++++++++++++++++
393+``autopilot.Platform`` - Functions for platform detection
394++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
395
396
397 .. automodule:: autopilot.platform
398
399=== modified file 'docs/api/testcase.rst'
400--- docs/api/testcase.rst 2013-04-05 04:15:17 +0000
401+++ docs/api/testcase.rst 2013-04-16 05:01:27 +0000
402@@ -1,5 +1,5 @@
403-``testcase`` - Base class for all Autopilot Test Cases
404-++++++++++++++++++++++++++++++++++++++++++++++++++++++
405+``autopilot.testcase`` - Base class for all Autopilot Test Cases
406+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
407
408
409 .. automodule:: autopilot.testcase
410
411=== modified file 'docs/conf.py'
412--- docs/conf.py 2013-04-15 20:42:55 +0000
413+++ docs/conf.py 2013-04-16 05:01:27 +0000
414@@ -101,7 +101,7 @@
415 pygments_style = 'sphinx'
416
417 # A list of ignored prefixes for module index sorting.
418-modindex_common_prefix = ['autopilot.']
419+# modindex_common_prefix = ['']
420
421 # nitpicky = True
422 # -- Options for HTML output ---------------------------------------------------

Subscribers

People subscribed via source and target branches