Merge lp:~ivo-kracht/launchpad/bug-728129 into lp:launchpad

Proposed by Ivo Kracht on 2012-07-05
Status: Merged
Approved by: j.c.sackett on 2012-07-05
Approved revision: no longer in the source branch.
Merged at revision: 15566
Proposed branch: lp:~ivo-kracht/launchpad/bug-728129
Merge into: lp:launchpad
Diff against target: 162 lines (+62/-1)
3 files modified
lib/lp/services/database/decoratedresultset.py (+8/-0)
lib/lp/services/database/tests/decoratedresultset.txt (+18/-1)
lib/lp/services/database/tests/test_decoratedresultset.py (+36/-0)
To merge this branch: bzr merge lp:~ivo-kracht/launchpad/bug-728129
Reviewer Review Type Date Requested Status
j.c.sackett (community) 2012-07-05 Approve on 2012-07-05
Review via email: mp+113612@code.launchpad.net

Description of the Change

I added the pre_iter_hook to the methods (first(), last(), any(), one()) as well as adding a new test file to make the original test work properly. Finally I adjusted the original test to fit the new conditions and added a test for the case that a method returns None.

Pre-imp call with adeuring

test:
./bin/test services -vvt decoratedresultset

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/services/database/decoratedresultset.py
  lib/lp/services/database/tests/decoratedresultset.txt
  lib/lp/services/database/tests/test_decoratedresultset.py

./lib/lp/services/database/tests/decoratedresultset.txt
       1: narrative uses a moin header.
      36: narrative uses a moin header.
      60: narrative uses a moin header.
      78: narrative uses a moin header.
      86: narrative uses a moin header.
      96: narrative uses a moin header.
     113: narrative uses a moin header.
     122: narrative uses a moin header.
     137: narrative uses a moin header.
     149: narrative uses a moin header.
     156: narrative uses a moin header.
     173: narrative uses a moin header.

Since it is nearly end of the work day i didn't have time to fix these errors

To post a comment you must log in.
j.c.sackett (jcsackett) wrote :

Thanks, Ivo. This looks good.

It looks like you've copy pasted test_decoratedresultset from another file; the headings are all wrong (it's talking about CVEs, buglinktarget, &c).

That said, I'm not sure that file is even needed--I gather from reading it it's meant to gather the doctest you modified, but that test is already gathered and run without it. Can you try deleting it and making sure your tests are run?

review: Needs Information
Abel Deuring (adeuring) wrote :

On 05.07.2012 19:41, j.c.sackett wrote:
> Review: Needs Information
>
> Thanks, Ivo. This looks good.
>
> It looks like you've copy pasted test_decoratedresultset from another file; the headings are all wrong (it's talking about CVEs, buglinktarget, &c).
>
> That said, I'm not sure that file is even needed--I gather from reading it it's meant to gather the doctest you modified, but that test is already gathered and run without it. Can you try deleting it and making sure your tests are run?
>

[playing the "proxy" for Ivo:]

right, the file was copied, and the comments need to be changed. But the
file itself is necessary: Without it, the doctest is simply not
executed. (Or do we have other ways to let the doctest really run?)

Ivo is currently "recovering" from his internship and back in college
tomorrow, so I'll "seize" his branch and fix the comments.

Abel

j.c.sackett (jcsackett) wrote :

I'll mark this as approved as the other resubmitted branch is now Approved as well. We'll have to manually mark this as Merged, I suspect, when the other lands.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/services/database/decoratedresultset.py'
2--- lib/lp/services/database/decoratedresultset.py 2012-03-27 00:15:07 +0000
3+++ lib/lp/services/database/decoratedresultset.py 2012-07-05 17:15:27 +0000
4@@ -167,12 +167,17 @@
5 else:
6 return self.decorate_or_none(value)
7
8+ def iterhook_one_elem(self, value):
9+ if value is not None and self.pre_iter_hook is not None:
10+ self.pre_iter_hook([value])
11+
12 def any(self, *args, **kwargs):
13 """See `IResultSet`.
14
15 :return: The decorated version of the returned value.
16 """
17 value = self.result_set.any(*args, **kwargs)
18+ self.iterhook_one_elem(value)
19 return self.decorate_or_none(value)
20
21 def first(self, *args, **kwargs):
22@@ -181,6 +186,7 @@
23 :return: The decorated version of the returned value.
24 """
25 value = self.result_set.first(*args, **kwargs)
26+ self.iterhook_one_elem(value)
27 return self.decorate_or_none(value)
28
29 def last(self, *args, **kwargs):
30@@ -189,6 +195,7 @@
31 :return: The decorated version of the returned value.
32 """
33 value = self.result_set.last(*args, **kwargs)
34+ self.iterhook_one_elem(value)
35 return self.decorate_or_none(value)
36
37 def one(self, *args, **kwargs):
38@@ -197,6 +204,7 @@
39 :return: The decorated version of the returned value.
40 """
41 value = self.result_set.one(*args, **kwargs)
42+ self.iterhook_one_elem(value)
43 return self.decorate_or_none(value)
44
45 def order_by(self, *args, **kwargs):
46
47=== modified file 'lib/lp/services/database/tests/decoratedresultset.txt'
48--- lib/lp/services/database/tests/decoratedresultset.txt 2011-12-20 08:55:34 +0000
49+++ lib/lp/services/database/tests/decoratedresultset.txt 2012-07-05 17:15:27 +0000
50@@ -25,10 +25,13 @@
51 >>> def result_decorator(distribution):
52 ... return "Dist name is: %s" % distribution.name
53
54+ >>> def pre_iter_hook(values):
55+ ... print len(values), "elements in result set"
56+
57 >>> from lp.services.database.decoratedresultset import (
58 ... DecoratedResultSet)
59 >>> decorated_result_set = DecoratedResultSet(
60- ... proxied_result_set, result_decorator)
61+ ... proxied_result_set, result_decorator, pre_iter_hook)
62
63 == copy() ==
64
65@@ -49,6 +52,7 @@
66
67 >>> for distro in result_copy:
68 ... distro
69+ 7 elements in result set
70 u'Dist name is: debian'
71 ...
72 u'Dist name is: ubuntutest'
73@@ -86,6 +90,7 @@
74
75 >>> orig_result = decorated_result_set.result_set.any()
76 >>> decorated_result_set.any() == result_decorator(orig_result)
77+ 1 elements in result set
78 True
79
80 == first() ==
81@@ -94,14 +99,24 @@
82 method and decorates the result:
83
84 >>> decorated_result_set.first()
85+ 1 elements in result set
86 u'Dist name is: debian'
87
88+pre_iter_hook is not called from methods like first() or one() which return
89+at most one row:
90+
91+ >>> empty_result_set = decorated_result_set.copy()
92+ >>> print empty_result_set.config(
93+ ... offset=empty_result_set.count()).first()
94+ None
95+
96 == last() ==
97
98 The decorated last() method calls the original result set's last()
99 method and decorates the result:
100
101 >>> decorated_result_set.last()
102+ 1 elements in result set
103 u'Dist name is: ubuntutest'
104
105 == order_by() ==
106@@ -114,6 +129,7 @@
107 ... Desc(Distribution.name))
108 >>> for dist in ordered_results:
109 ... dist
110+ 7 elements in result set
111 u'Dist name is: ubuntutest'
112 ...
113 u'Dist name is: debian'
114@@ -124,6 +140,7 @@
115 method and decorates the result:
116
117 >>> decorated_result_set.config(offset=2, limit=1).one()
118+ 1 elements in result set
119 u'Dist name is: redhat'
120
121 >>> result_decorator(decorated_result_set.result_set.one())
122
123=== added file 'lib/lp/services/database/tests/test_decoratedresultset.py'
124--- lib/lp/services/database/tests/test_decoratedresultset.py 1970-01-01 00:00:00 +0000
125+++ lib/lp/services/database/tests/test_decoratedresultset.py 2012-07-05 17:15:27 +0000
126@@ -0,0 +1,36 @@
127+# Copyright 2009 Canonical Ltd. This software is licensed under the
128+# GNU Affero General Public License version 3 (see the file LICENSE).
129+
130+"""Test harness for running the buglinktarget.txt interface test
131+
132+This module will run the interface test against the CVE, Specification and
133+Question implementations of that interface.
134+"""
135+
136+__metaclass__ = type
137+
138+__all__ = []
139+
140+import unittest
141+
142+from lp.testing.layers import DatabaseFunctionalLayer
143+from lp.testing.systemdocs import (
144+ LayeredDocFileSuite,
145+ setUp,
146+ tearDown,
147+ )
148+
149+
150+def test_suite():
151+ suite = unittest.TestSuite()
152+
153+ test = LayeredDocFileSuite(
154+ 'decoratedresultset.txt',
155+ setUp=setUp, tearDown=tearDown,
156+ layer=DatabaseFunctionalLayer)
157+ suite.addTest(test)
158+ return suite
159+
160+
161+if __name__ == '__main__':
162+ unittest.main()