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
=== modified file 'autopilot/__init__.py'
--- autopilot/__init__.py 2012-05-07 17:38:00 +0000
+++ autopilot/__init__.py 2013-04-16 05:01:27 +0000
@@ -6,7 +6,17 @@
6# under the terms of the GNU General Public License version 3, as published6# under the terms of the GNU General Public License version 3, as published
7# by the Free Software Foundation.7# by the Free Software Foundation.
88
9"""An automated test runner and driver for Unity"""9
1010version = '1.3'
1111
12version = "1.0"12
13class BackendException(RuntimeError):
14
15 """An error occured while trying to initialise an autopilot backend."""
16
17 def __init__(self, original_exception):
18 super(BackendException, self).__init__(
19 "Error while initialising backend. Original exception was: " \
20 + original_exception.message
21 )
22 self.original_exception = original_exception
1323
=== modified file 'autopilot/display/__init__.py'
--- autopilot/display/__init__.py 2013-04-08 03:46:47 +0000
+++ autopilot/display/__init__.py 2013-04-16 05:01:27 +0000
@@ -90,13 +90,23 @@
90 def create(preferred_variant=''):90 def create(preferred_variant=''):
91 """Get an instance of the Display class.91 """Get an instance of the Display class.
9292
93 If variant is specified, it should be a string that specifies a backend to93 :param preferred_variant: A string containing a hint as to which variant you
94 use. However, this hint can be ignored - autopilot will prefer to return a94 would like. If left blank, autopilot will pick a suitable
95 variant other than the one requested, rather than fail to return anything at95 variant for you. Specifying a variant will guarantee that either that
96 all.96 variant is returned, or an exception is raised.
9797
98 If autopilot cannot instantate any of the possible backends, a RuntimeError98 possible variants are:
99 will be raised.99
100 * ``X11`` - Get display information from X11.
101 * ``UPA`` - Get display information from the ubuntu platform API.
102
103 :raises: RuntimeError if autopilot cannot instantate any of the possible
104 backends.
105 :raises: RuntimeError if the preferred_variant is specified and is not
106 one of the possible backends for this device class.
107 :raises: :class:`~autopilot.BackendException` if the preferred_variant is
108 set, but that variant could not be instantiated.
109
100 """110 """
101 def get_x11_display():111 def get_x11_display():
102 from autopilot.display._X11 import Display112 from autopilot.display._X11 import Display
103113
=== modified file 'autopilot/input/__init__.py'
--- autopilot/input/__init__.py 2013-04-08 03:46:47 +0000
+++ autopilot/input/__init__.py 2013-04-16 05:01:27 +0000
@@ -17,9 +17,11 @@
17events (possibly UInput).17events (possibly UInput).
1818
19Test authors should instantiate the appropriate class using the ``create`` method19Test authors should instantiate the appropriate class using the ``create`` method
20on each class. Tests can provide a hint to this method to suggest that a particular20on each class. Calling ``create()`` with no arguments will get an instance of the
21subsystem be used. However, autopilot will prefer to return a subsystem other than21specified class that suits the current platform. In this case, autopilot will
22the one specified, if the requested subsystem is unavailable.22do it's best to pick a suitable variant. Calling ``create`` with a variant name
23will result in that specific variant type being returned, or, if it cannot be created,
24an exception will be raised. The exception type varies from variant to variant.
2325
24There are three basic input types available:26There are three basic input types available:
2527
@@ -49,12 +51,23 @@
49 def create(preferred_variant=''):51 def create(preferred_variant=''):
50 """Get an instance of the :py:class:`Keyboard` class.52 """Get an instance of the :py:class:`Keyboard` class.
5153
52 :param preferred_variant: A string containing a hint as to which variant you54 :param preferred_variant: A string containing a hint as to which variant
53 would like. However, this hint can be ignored - autopilot will prefer to55 you would like. If left blank, autopilot will pick a suitable
54 return a keyboard variant other than the one requested, rather than fail56 variant for you. Specifying a variant will guarantee that either that
55 to return anything at all.57 variant is returned, or an exception is raised.
56 :raises: a RuntimeError will be raised if autopilot cannot instantate any of58
57 the possible backends.59 possible variants are:
60
61 * ``X11`` - Generate keyboard events using the X11 client libraries.
62 * ``UInput`` - Use UInput kernel-level device driver.
63
64 :raises: RuntimeError if autopilot cannot instantate any of the possible
65 backends.
66 :raises: RuntimeError if the preferred_variant is specified and is not
67 one of the possible backends for this device class.
68 :raises: :class:`~autopilot.BackendException` if the preferred_variant is
69 set, but that variant could not be instantiated.
70
5871
59 """72 """
60 def get_x11_kb():73 def get_x11_kb():
@@ -167,11 +180,20 @@
167 """Get an instance of the :py:class:`Mouse` class.180 """Get an instance of the :py:class:`Mouse` class.
168181
169 :param preferred_variant: A string containing a hint as to which variant you182 :param preferred_variant: A string containing a hint as to which variant you
170 would like. However, this hint can be ignored - autopilot will prefer to183 would like. If left blank, autopilot will pick a suitable
171 return a mouse variant other than the one requested, rather than fail184 variant for you. Specifying a variant will guarantee that either that
172 to return anything at all.185 variant is returned, or an exception is raised.
173 :raises: a RuntimeError will be raised if autopilot cannot instantate any of186
174 the possible backends.187 possible variants are:
188
189 * ``X11`` - Generate mouse events using the X11 client libraries.
190
191 :raises: RuntimeError if autopilot cannot instantate any of the possible
192 backends.
193 :raises: RuntimeError if the preferred_variant is specified and is not
194 one of the possible backends for this device class.
195 :raises: :class:`~autopilot.BackendException` if the preferred_variant is
196 set, but that variant could not be instantiated.
175197
176 """198 """
177 def get_x11_mouse():199 def get_x11_mouse():
@@ -262,11 +284,21 @@
262 """Get an instance of the :py:class:`Touch` class.284 """Get an instance of the :py:class:`Touch` class.
263285
264 :param preferred_variant: A string containing a hint as to which variant you286 :param preferred_variant: A string containing a hint as to which variant you
265 would like. However, this hint can be ignored - autopilot will prefer to287 would like. If left blank, autopilot will pick a suitable
266 return a touch variant other than the one requested, rather than fail288 variant for you. Specifying a variant will guarantee that either that
267 to return anything at all.289 variant is returned, or an exception is raised.
268 :raises: a RuntimeError will be raised if autopilot cannot instantate any of290
269 the possible backends.291 possible variants are:
292
293 * ``UInput`` - Use UInput kernel-level device driver.
294
295 :raises: RuntimeError if autopilot cannot instantate any of the possible
296 backends.
297 :raises: RuntimeError if the preferred_variant is specified and is not
298 one of the possible backends for this device class.
299 :raises: :class:`~autopilot.BackendException` if the preferred_variant is
300 set, but that variant could not be instantiated.
301
270302
271 """303 """
272 def get_uinput_touch():304 def get_uinput_touch():
273305
=== modified file 'autopilot/process/__init__.py'
--- autopilot/process/__init__.py 2013-04-15 03:39:09 +0000
+++ autopilot/process/__init__.py 2013-04-16 05:01:27 +0000
@@ -58,11 +58,21 @@
58 """Get an instance of the :py:class:`ProcessManager` class.58 """Get an instance of the :py:class:`ProcessManager` class.
5959
60 :param preferred_variant: A string containing a hint as to which variant you60 :param preferred_variant: A string containing a hint as to which variant you
61 would like. However, this hint can be ignored - autopilot will prefer to61 would like. If left blank, autopilot will pick a suitable
62 return a keyboard variant other than the one requested, rather than fail62 variant for you. Specifying a variant will guarantee that either that
63 to return anything at all.63 variant is returned, or an exception is raised.
64 :raises: a RuntimeError will be raised if autopilot cannot instantate any of64
65 the possible backends.65 possible variants are:
66
67 * ``BAMF`` - Get process information using the BAMF Application Matching Framework.
68
69 :raises: RuntimeError if autopilot cannot instantate any of the possible
70 backends.
71 :raises: RuntimeError if the preferred_variant is specified and is not
72 one of the possible backends for this device class.
73 :raises: :class:`~autopilot.BackendException` if the preferred_variant is
74 set, but that variant could not be instantiated.
75
66 """76 """
67 def get_bamf_pm():77 def get_bamf_pm():
68 from autopilot.process._bamf import ProcessManager78 from autopilot.process._bamf import ProcessManager
6979
=== added file 'autopilot/tests/test_custom_exceptions.py'
--- autopilot/tests/test_custom_exceptions.py 1970-01-01 00:00:00 +0000
+++ autopilot/tests/test_custom_exceptions.py 2013-04-16 05:01:27 +0000
@@ -0,0 +1,31 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2# Copyright 2013 Canonical
3# Author: Thomi Richards
4#
5# This program is free software: you can redistribute it and/or modify it
6# under the terms of the GNU General Public License version 3, as published
7# by the Free Software Foundation.
8
9
10from testtools import TestCase
11from testtools.matchers import Equals, IsInstance
12
13from autopilot import BackendException
14
15class BackendExceptionTests(TestCase):
16
17 def test_must_wrap_exception(self):
18 """BackendException must be able to wrap another exception instance."""
19 err = BackendException(RuntimeError("Hello World"))
20 self.assertThat(err.original_exception, IsInstance(RuntimeError))
21 self.assertThat(err.original_exception.message, Equals("Hello World"))
22
23 def test_dunder_str(self):
24 err = BackendException(RuntimeError("Hello World"))
25 self.assertThat(str(err),
26 Equals("Error while initialising backend. Original exception was: Hello World"))
27
28 def test_dunder_repr(self):
29 err = BackendException(RuntimeError("Hello World"))
30 self.assertThat(repr(err),
31 Equals("BackendException('Error while initialising backend. Original exception was: Hello World',)"))
032
=== modified file 'autopilot/utilities.py'
--- autopilot/utilities.py 2013-04-08 01:05:45 +0000
+++ autopilot/utilities.py 2013-04-16 05:01:27 +0000
@@ -20,12 +20,17 @@
20import time20import time
21from functools import wraps21from functools import wraps
2222
23from autopilot import BackendException
24
2325
24def _pick_variant(variants, preferred_variant):26def _pick_variant(variants, preferred_variant):
25 possible_backends = variants.keys()27 possible_backends = variants.keys()
26 get_debug_logger().debug("Possible variants: %s", ','.join(possible_backends))28 get_debug_logger().debug("Possible variants: %s", ','.join(possible_backends))
27 if preferred_variant in possible_backends:29 if preferred_variant:
28 possible_backends.sort(lambda a,b: -1 if a == preferred_variant else 0)30 if preferred_variant in possible_backends:
31 possible_backends.sort(lambda a,b: -1 if a == preferred_variant else 0)
32 else:
33 raise RuntimeError("Unknown backend '%s'" % (preferred_variant))
29 failure_reasons = []34 failure_reasons = []
30 for be in possible_backends:35 for be in possible_backends:
31 try:36 try:
@@ -33,6 +38,8 @@
33 except Exception as e:38 except Exception as e:
34 get_debug_logger().warning("Can't create variant %s: %r", be, e)39 get_debug_logger().warning("Can't create variant %s: %r", be, e)
35 failure_reasons.append('%s: %r' % (be, e))40 failure_reasons.append('%s: %r' % (be, e))
41 if preferred_variant != '':
42 raise BackendException(e)
36 raise RuntimeError("Unable to instantiate any backends\n%s" % '\n'.join(failure_reasons))43 raise RuntimeError("Unable to instantiate any backends\n%s" % '\n'.join(failure_reasons))
3744
3845
3946
=== modified file 'docs/_templates/indexcontent.html'
--- docs/_templates/indexcontent.html 2013-04-15 03:33:21 +0000
+++ docs/_templates/indexcontent.html 2013-04-16 05:01:27 +0000
@@ -12,7 +12,7 @@
12 </td>12 </td>
13 <td width="50%">13 <td width="50%">
14 <p class="biglink">14 <p class="biglink">
15 <a class="biglink" href="{{ pathto("api/autopilot") }}">API Reference</a><br/>15 <a class="biglink" href="{{ pathto("api/index") }}">API Reference</a><br/>
16 <span class="linkdescr">API reference documentation for Autopilot.</span>16 <span class="linkdescr">API reference documentation for Autopilot.</span>
17 </p>17 </p>
18 </td>18 </td>
1919
=== modified file 'docs/api/autopilot.rst'
--- docs/api/autopilot.rst 2013-04-14 21:56:27 +0000
+++ docs/api/autopilot.rst 2013-04-16 05:01:27 +0000
@@ -1,10 +1,8 @@
1:orphan:1``autopilot`` - Global stuff
22++++++++++++++++++++++++++++
3Autopilot API Documentation3
4===========================4
55.. automodule:: autopilot
6.. toctree::6 :members:
7 :maxdepth: 17 :undoc-members:
8 :glob:8
9
10 *
119
=== modified file 'docs/api/display.rst'
--- docs/api/display.rst 2013-04-05 05:26:23 +0000
+++ docs/api/display.rst 2013-04-16 05:01:27 +0000
@@ -1,5 +1,5 @@
1``display`` - Get information about the current display(s)1``autopilot.display`` - Get information about the current display(s)
2++++++++++++++++++++++++++++++++++++++++++++++++++++++++++2++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
44
5.. automodule:: autopilot.display5.. automodule:: autopilot.display
66
=== modified file 'docs/api/emulators.rst'
--- docs/api/emulators.rst 2013-04-15 01:15:52 +0000
+++ docs/api/emulators.rst 2013-04-16 05:01:27 +0000
@@ -1,5 +1,5 @@
1``emulators`` - Backwards compatibility for autopilot v1.21``autopilot.emulators`` - Backwards compatibility for autopilot v1.2
2++++++++++++++++++++++++++++++++++++++++++++++++++++++++++2++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
44
5.. module autopilot.emulators5.. module autopilot.emulators
66
=== modified file 'docs/api/gestures.rst'
--- docs/api/gestures.rst 2013-04-05 04:57:25 +0000
+++ docs/api/gestures.rst 2013-04-16 05:01:27 +0000
@@ -1,5 +1,5 @@
1``gestures`` - Gestural and multi-touch support1``autopilot.gestures`` - Gestural and multi-touch support
2+++++++++++++++++++++++++++++++++++++++++++++++2+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
44
5.. automodule:: autopilot.gestures5.. automodule:: autopilot.gestures
66
=== added file 'docs/api/index.rst'
--- docs/api/index.rst 1970-01-01 00:00:00 +0000
+++ docs/api/index.rst 2013-04-16 05:01:27 +0000
@@ -0,0 +1,10 @@
1:orphan:
2
3Autopilot API Documentation
4===========================
5
6.. toctree::
7 :maxdepth: 1
8 :glob:
9
10 *
011
=== modified file 'docs/api/input.rst'
--- docs/api/input.rst 2013-04-05 05:26:23 +0000
+++ docs/api/input.rst 2013-04-16 05:01:27 +0000
@@ -1,5 +1,5 @@
1``input`` - Generate keyboard, mouse, and touch input events1``autopilot.input`` - Generate keyboard, mouse, and touch input events
2++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++2++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
44
5.. automodule:: autopilot.input5.. automodule:: autopilot.input
66
=== modified file 'docs/api/introspection.rst'
--- docs/api/introspection.rst 2013-04-15 01:00:21 +0000
+++ docs/api/introspection.rst 2013-04-16 05:01:27 +0000
@@ -1,5 +1,5 @@
1``introspection`` - Autopilot introspection internals1``autopilot.introspection`` - Autopilot introspection internals
2+++++++++++++++++++++++++++++++++++++++++++++++++++++2+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
44
5.. automodule:: autopilot.introspection5.. automodule:: autopilot.introspection
66
=== modified file 'docs/api/matchers.rst'
--- docs/api/matchers.rst 2013-04-05 04:15:17 +0000
+++ docs/api/matchers.rst 2013-04-16 05:01:27 +0000
@@ -1,5 +1,5 @@
1``matchers`` - Custom matchers for test assertions1``autopilot.matchers`` - Custom matchers for test assertions
2++++++++++++++++++++++++++++++++++++++++++++++++++2++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
44
5.. automodule:: autopilot.matchers5.. automodule:: autopilot.matchers
66
=== modified file 'docs/api/platform.rst'
--- docs/api/platform.rst 2013-04-05 04:15:17 +0000
+++ docs/api/platform.rst 2013-04-16 05:01:27 +0000
@@ -1,5 +1,5 @@
1``Platform`` - Functions for platform detection1``autopilot.Platform`` - Functions for platform detection
2+++++++++++++++++++++++++++++++++++++++++++++++2+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
44
5.. automodule:: autopilot.platform5.. automodule:: autopilot.platform
66
=== modified file 'docs/api/testcase.rst'
--- docs/api/testcase.rst 2013-04-05 04:15:17 +0000
+++ docs/api/testcase.rst 2013-04-16 05:01:27 +0000
@@ -1,5 +1,5 @@
1``testcase`` - Base class for all Autopilot Test Cases1``autopilot.testcase`` - Base class for all Autopilot Test Cases
2++++++++++++++++++++++++++++++++++++++++++++++++++++++2++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
44
5.. automodule:: autopilot.testcase5.. automodule:: autopilot.testcase
66
=== modified file 'docs/conf.py'
--- docs/conf.py 2013-04-15 20:42:55 +0000
+++ docs/conf.py 2013-04-16 05:01:27 +0000
@@ -101,7 +101,7 @@
101pygments_style = 'sphinx'101pygments_style = 'sphinx'
102102
103# A list of ignored prefixes for module index sorting.103# A list of ignored prefixes for module index sorting.
104modindex_common_prefix = ['autopilot.']104# modindex_common_prefix = ['']
105105
106# nitpicky = True106# nitpicky = True
107# -- Options for HTML output ---------------------------------------------------107# -- Options for HTML output ---------------------------------------------------

Subscribers

People subscribed via source and target branches