Merge lp:~thomir-deactivatedaccount/autopilot/fix-select-single into lp:autopilot/1.3

Proposed by Thomi Richards
Status: Merged
Approved by: Martin Pitt
Approved revision: 337
Merged at revision: 328
Proposed branch: lp:~thomir-deactivatedaccount/autopilot/fix-select-single
Merge into: lp:autopilot/1.3
Prerequisite: lp:~thomir-deactivatedaccount/autopilot/fix-state-not-found
Diff against target: 95 lines (+17/-10)
3 files modified
autopilot/introspection/dbus.py (+5/-2)
autopilot/tests/functional/test_dbus_query.py (+10/-6)
autopilot/tests/unit/test_exceptions.py (+2/-2)
To merge this branch: bzr merge lp:~thomir-deactivatedaccount/autopilot/fix-select-single
Reviewer Review Type Date Requested Status
Martin Pitt (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+185678@code.launchpad.net

Commit message

Fix select_single inconsistency.

Description of the change

This branch fixes the issue with select_single where it should raise an exception instead of returning None.

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

The docstring still says

        If nothing is returned from the query, this method returns None.

which needs to be updated.

Otherwise, LGTM.

review: Needs Fixing
337. By Thomi Richards

Fix issues arising from code review.

Revision history for this message
Martin Pitt (pitti) wrote :

LGTM, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'autopilot/introspection/dbus.py'
2--- autopilot/introspection/dbus.py 2013-09-16 13:45:13 +0000
3+++ autopilot/introspection/dbus.py 2013-09-16 13:45:13 +0000
4@@ -359,7 +359,8 @@
5 app.select_single('QPushButton', objectName='clickme')
6 # returns a QPushButton whose 'objectName' property is 'clickme'.
7
8- If nothing is returned from the query, this method returns None.
9+ If nothing is returned from the query, this method raises
10+ StateNotFoundError.
11
12 :param type_name: Either a string naming the type you want, or a class
13 of the appropriate type (the latter case is for overridden emulator
14@@ -371,6 +372,8 @@
15 :raises TypeError: if neither *type_name* or keyword filters are
16 provided.
17
18+ :raises StateNotFoundError: if the requested object was not found.
19+
20 .. seealso::
21 Tutorial Section :ref:`custom_emulators`
22
23@@ -379,7 +382,7 @@
24 if len(instances) > 1:
25 raise ValueError("More than one item was returned for query")
26 if not instances:
27- return None
28+ raise StateNotFoundError(type_name, **kwargs)
29 return instances[0]
30
31 def select_many(self, type_name='*', **kwargs):
32
33=== modified file 'autopilot/tests/functional/test_dbus_query.py'
34--- autopilot/tests/functional/test_dbus_query.py 2013-07-29 10:29:37 +0000
35+++ autopilot/tests/functional/test_dbus_query.py 2013-09-16 13:45:13 +0000
36@@ -26,6 +26,7 @@
37
38 from autopilot.testcase import AutopilotTestCase
39 from testtools.matchers import Equals, NotEquals, raises
40+from autopilot.introspection.dbus import StateNotFoundError
41
42
43 class DbusQueryTests(AutopilotTestCase):
44@@ -126,10 +127,10 @@
45 fn = lambda: app.select_single()
46 self.assertThat(fn, raises(TypeError))
47
48- def test_select_single_no_match_returns_none(self):
49+ def test_select_single_no_match_raises_exception(self):
50 app = self.start_fully_featured_app()
51- failed_match = app.select_single("QMadeupType")
52- self.assertThat(failed_match, Equals(None))
53+ match_fn = lambda: app.select_single("QMadeupType")
54+ self.assertThat(match_fn, raises(StateNotFoundError('QMadeupType')))
55
56 def test_select_single_parameters_only(self):
57 app = self.start_fully_featured_app()
58@@ -138,10 +139,13 @@
59 self.assertThat(titled_help, NotEquals(None))
60 self.assertThat(titled_help.title, Equals('Help'))
61
62- def test_select_single_parameters_no_match_returns_none(self):
63+ def test_select_single_parameters_no_match_raises_exception(self):
64 app = self.start_fully_featured_app()
65- failed_match = app.select_single(title="Non-existant object")
66- self.assertThat(failed_match, Equals(None))
67+ match_fn = lambda: app.select_single(title="Non-existant object")
68+ self.assertThat(
69+ match_fn,
70+ raises(StateNotFoundError(title="Non-existant object"))
71+ )
72
73 def test_select_single_returning_multiple_raises(self):
74 app = self.start_fully_featured_app()
75
76=== modified file 'autopilot/tests/unit/test_exceptions.py'
77--- autopilot/tests/unit/test_exceptions.py 2013-09-16 13:45:13 +0000
78+++ autopilot/tests/unit/test_exceptions.py 2013-09-16 13:45:13 +0000
79@@ -65,7 +65,7 @@
80 )
81 self.assertThat(
82 unicode(err),
83- Equals("State not found with filters {'foo': 'bar'}.")
84+ Equals(u"State not found with filters {'foo': 'bar'}.")
85 )
86
87 def test_can_be_constructed_with_class_name_and_filters(self):
88@@ -83,6 +83,6 @@
89 )
90 self.assertThat(
91 unicode(err),
92- Equals("State not found for class 'MyClass'"
93+ Equals(u"State not found for class 'MyClass'"
94 " and filters {'foo': 'bar'}.")
95 )

Subscribers

People subscribed via source and target branches

to all changes: