Merge lp:~mandel/ubuntuone-dev-tools/refactor-testcase into lp:ubuntuone-dev-tools
- refactor-testcase
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Manuel de la Peña |
Approved revision: | 55 |
Merged at revision: | 49 |
Proposed branch: | lp:~mandel/ubuntuone-dev-tools/refactor-testcase |
Merge into: | lp:ubuntuone-dev-tools |
Diff against target: |
320 lines (+149/-98) 6 files modified
setup.py (+2/-1) ubuntuone/devtools/services/tests/test_dbus.py (+1/-1) ubuntuone/devtools/testcase.py (+25/-0) ubuntuone/devtools/testcases/__init__.py (+2/-95) ubuntuone/devtools/testcases/dbus.py (+118/-0) ubuntuone/devtools/testing/txcheck.py (+1/-1) |
To merge this branch: | bzr merge lp:~mandel/ubuntuone-dev-tools/refactor-testcase |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
dobey (community) | Approve | ||
Diego Sarmentero (community) | Approve | ||
Review via email: mp+82868@code.launchpad.net |
Commit message
Refactor the dbus test case to accommodate the code for the addition of extra test cases.
Description of the change
Refactor the dbus test case to accommodate the code for the addition of extra test cases.
dobey (dobey) : | # |
dobey (dobey) wrote : | # |
+"""Matain old API."""
Maintain, I presume? :)
dobey (dobey) wrote : | # |
Oh, and should probably update the year in the Copyright headers for the new files in testcases/ also.
dobey (dobey) : | # |
Ubuntu One Auto Pilot (otto-pilot) wrote : | # |
The attempt to merge lp:~mandel/ubuntuone-dev-tools/refactor-testcase into lp:ubuntuone-dev-tools failed. Below is the output from the failed tests.
ubuntuone.
DBusTestCase
runTest ... [OK]
ubuntuone.
TestWithDBus
test_
test_
ubuntuone.
BaseTestCase
runTest ... [OK]
ubuntuone.
TestSkipBasic
test_skip_class ... [OK]
test_
ubuntuone.
TestCheckTwis
test_
test_bare_super ... [OK]
test_
test_
test_
test_
test_
test_
test_
TestTwistedCh
test_
test_
twisted.
TestCase
runTest ... [OK]
-------
Ran 18 tests in 0.259s
PASSED (successes=18)
Name Stmts Exec Cover
-------
ubuntuone/__init__ 1 0 0%
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
Ubuntu One Auto Pilot (otto-pilot) wrote : | # |
The attempt to merge lp:~mandel/ubuntuone-dev-tools/refactor-testcase into lp:ubuntuone-dev-tools failed. Below is the output from the failed tests.
ubuntuone.
DBusTestCase
runTest ... [OK]
ubuntuone.
TestWithDBus
test_
test_
ubuntuone.
BaseTestCase
runTest ... [OK]
ubuntuone.
TestSkipBasic
test_skip_class ... [OK]
test_
ubuntuone.
TestCheckTwis
test_
test_bare_super ... [OK]
test_
test_
test_
test_
test_
test_
test_
TestTwistedCh
test_
test_
twisted.
TestCase
runTest ... [OK]
-------
Ran 18 tests in 0.283s
PASSED (successes=18)
Name Stmts Exec Cover
-------
ubuntuone/__init__ 1 0 0%
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
Ubuntu One Auto Pilot (otto-pilot) wrote : | # |
There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.
Preview Diff
1 | === modified file 'setup.py' |
2 | --- setup.py 2011-11-14 22:16:40 +0000 |
3 | +++ setup.py 2011-11-23 11:17:24 +0000 |
4 | @@ -52,7 +52,8 @@ |
5 | 'ubuntuone.devtools', |
6 | 'ubuntuone.devtools.reactors', |
7 | 'ubuntuone.devtools.services', |
8 | - 'ubuntuone.devtools.testing'], |
9 | + 'ubuntuone.devtools.testing', |
10 | + 'ubuntuone.devtools.testcases'], |
11 | extra_path='ubuntuone-dev-tools', |
12 | scripts=['bin/u1lint', |
13 | 'bin/u1trial', |
14 | |
15 | === modified file 'ubuntuone/devtools/services/tests/test_dbus.py' |
16 | --- ubuntuone/devtools/services/tests/test_dbus.py 2011-11-18 23:09:59 +0000 |
17 | +++ ubuntuone/devtools/services/tests/test_dbus.py 2011-11-23 11:17:24 +0000 |
18 | @@ -3,7 +3,7 @@ |
19 | import os |
20 | import shutil |
21 | |
22 | -from ubuntuone.devtools.testcase import DBusTestCase |
23 | +from ubuntuone.devtools.testcases.dbus import DBusTestCase |
24 | from ubuntuone.devtools.services.dbus import DBusRunner |
25 | from urllib import unquote |
26 | |
27 | |
28 | === added file 'ubuntuone/devtools/testcase.py' |
29 | --- ubuntuone/devtools/testcase.py 1970-01-01 00:00:00 +0000 |
30 | +++ ubuntuone/devtools/testcase.py 2011-11-23 11:17:24 +0000 |
31 | @@ -0,0 +1,25 @@ |
32 | +# -*- coding: utf-8 -*- |
33 | +# |
34 | +# Copyright 2011 Canonical Ltd. |
35 | +# |
36 | +# This program is free software: you can redistribute it and/or modify it |
37 | +# under the terms of the GNU General Public License version 3, as published |
38 | +# by the Free Software Foundation. |
39 | +# |
40 | +# This program is distributed in the hope that it will be useful, but |
41 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
42 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
43 | +# PURPOSE. See the GNU General Public License for more details. |
44 | +# |
45 | +# You should have received a copy of the GNU General Public License along |
46 | +# with this program. If not, see <http://www.gnu.org/licenses/>. |
47 | +"""Maintain old API.""" |
48 | + |
49 | +import warnings |
50 | +warnings.warn( |
51 | + 'Deprecated import path; use ubuntuone.devtools.testcases' |
52 | + 'instead.', DeprecationWarning, stacklevel=2) |
53 | + |
54 | +# pylint: disable=W0401,W0614 |
55 | +from ubuntuone.devtools.testcases import * |
56 | +from ubuntuone.devtools.testcases.dbus import * |
57 | |
58 | === added directory 'ubuntuone/devtools/testcases' |
59 | === renamed file 'ubuntuone/devtools/testcase.py' => 'ubuntuone/devtools/testcases/__init__.py' |
60 | --- ubuntuone/devtools/testcase.py 2011-06-14 13:40:37 +0000 |
61 | +++ ubuntuone/devtools/testcases/__init__.py 2011-11-23 11:17:24 +0000 |
62 | @@ -1,8 +1,6 @@ |
63 | # -*- coding: utf-8 -*- |
64 | - |
65 | -# Author: Guillermo Gonzalez <guillermo.gonzalez@canonical.com> |
66 | # |
67 | -# Copyright 2009-2010 Canonical Ltd. |
68 | +# Copyright 2009-2011 Canonical Ltd. |
69 | # |
70 | # This program is free software: you can redistribute it and/or modify it |
71 | # under the terms of the GNU General Public License version 3, as published |
72 | @@ -27,31 +25,9 @@ |
73 | |
74 | from functools import wraps |
75 | |
76 | -from twisted.internet import defer |
77 | from twisted.trial.unittest import TestCase, SkipTest |
78 | |
79 | -# DBusRunner for DBusTestCase using tests |
80 | -from ubuntuone.devtools.services.dbus import DBusRunner |
81 | - |
82 | - |
83 | -# pylint: disable=F0401,C0103 |
84 | -try: |
85 | - import dbus |
86 | -except ImportError: |
87 | - dbus = None |
88 | - |
89 | -try: |
90 | - import dbus.service as service |
91 | -except ImportError: |
92 | - service = None |
93 | - |
94 | -try: |
95 | - from dbus.mainloop.glib import DBusGMainLoop |
96 | -except ImportError: |
97 | - DBusGMainLoop = None |
98 | - |
99 | - |
100 | -# pylint: enable=F0401,C0103 |
101 | + |
102 | @contextlib.contextmanager |
103 | def environ(env_var, new_value): |
104 | """context manager to replace/add an environ value""" |
105 | @@ -128,17 +104,6 @@ |
106 | # pylint: enable=C0103 |
107 | |
108 | |
109 | -class InvalidSessionBus(Exception): |
110 | - """Error when we are connected to the wrong session bus in tests.""" |
111 | - |
112 | - |
113 | -class FakeDBusInterface(object): |
114 | - """A fake DBusInterface...""" |
115 | - |
116 | - def shutdown(self, with_restart=False): |
117 | - """...that only knows how to go away""" |
118 | - |
119 | - |
120 | class BaseTestCase(TestCase): |
121 | """Base TestCase with helper methods to handle temp dir. |
122 | |
123 | @@ -199,61 +164,3 @@ |
124 | if os.path.exists(parent): |
125 | os.chmod(parent, 0755) |
126 | os.makedirs(path) |
127 | - |
128 | - |
129 | -@skipIf(dbus is None or service is None or DBusGMainLoop is None, |
130 | - "The test requires dbus.") |
131 | -class DBusTestCase(BaseTestCase): |
132 | - """Test the DBus event handling.""" |
133 | - |
134 | - def required_services(self): |
135 | - """Return the list of required services for DBusTestCase.""" |
136 | - services = super(DBusTestCase, self).required_services() |
137 | - services.extend([DBusRunner]) |
138 | - return services |
139 | - |
140 | - @defer.inlineCallbacks |
141 | - def setUp(self): |
142 | - """Setup the infrastructure fo the test (dbus service).""" |
143 | - # Class 'BaseTestCase' has no 'setUp' member |
144 | - # pylint: disable=E1101 |
145 | - # dbus modules will be imported by the decorator |
146 | - # pylint: disable=E0602 |
147 | - yield super(DBusTestCase, self).setUp() |
148 | - |
149 | - # We need to ensure DBUS_SESSION_BUS_ADDRESS is private here |
150 | - from urllib import unquote |
151 | - bus_address = os.environ.get('DBUS_SESSION_BUS_ADDRESS', None) |
152 | - if os.path.dirname(unquote(bus_address.split(',')[0].split('=')[1])) \ |
153 | - != os.path.dirname(os.getcwd()): |
154 | - raise InvalidSessionBus('DBUS_SESSION_BUS_ADDRES is wrong.') |
155 | - |
156 | - # Set up the main loop and bus connection |
157 | - self.loop = DBusGMainLoop(set_as_default=True) |
158 | - self.bus = dbus.bus.BusConnection(address_or_type=bus_address, |
159 | - mainloop=self.loop) |
160 | - |
161 | - # Monkeypatch the dbus.SessionBus/SystemBus methods, to ensure we |
162 | - # always point at our own private bus instance. |
163 | - self.patch(dbus, 'SessionBus', lambda: self.bus) |
164 | - self.patch(dbus, 'SystemBus', lambda: self.bus) |
165 | - |
166 | - # Check that we are on the correct bus for real |
167 | -# Disable this for now, because our tests are extremely broken :( |
168 | -# bus_names = self.bus.list_names() |
169 | -# if len(bus_names) > 2: |
170 | -# raise InvalidSessionBus('Too many bus connections: %s (%r)' % |
171 | -# (len(bus_names), bus_names)) |
172 | - |
173 | - # monkeypatch busName.__del__ to avoid errors on gc |
174 | - # we take care of releasing the name in shutdown |
175 | - service.BusName.__del__ = lambda _: None |
176 | - yield self.bus.set_exit_on_disconnect(False) |
177 | - self.signal_receivers = set() |
178 | - |
179 | - @defer.inlineCallbacks |
180 | - def tearDown(self): |
181 | - """Cleanup the test.""" |
182 | - yield self.bus.flush() |
183 | - yield self.bus.close() |
184 | - yield super(DBusTestCase, self).tearDown() |
185 | |
186 | === added file 'ubuntuone/devtools/testcases/dbus.py' |
187 | --- ubuntuone/devtools/testcases/dbus.py 1970-01-01 00:00:00 +0000 |
188 | +++ ubuntuone/devtools/testcases/dbus.py 2011-11-23 11:17:24 +0000 |
189 | @@ -0,0 +1,118 @@ |
190 | +# -*- coding: utf-8 -*- |
191 | +# |
192 | +# Copyright 2009-2011 Canonical Ltd. |
193 | +# |
194 | +# This program is free software: you can redistribute it and/or modify it |
195 | +# under the terms of the GNU General Public License version 3, as published |
196 | +# by the Free Software Foundation. |
197 | +# |
198 | +# This program is distributed in the hope that it will be useful, but |
199 | +# WITHOUT ANY WARRANTY; without even the implied warranties of |
200 | +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
201 | +# PURPOSE. See the GNU General Public License for more details. |
202 | +# |
203 | +# You should have received a copy of the GNU General Public License along |
204 | +# with this program. If not, see <http://www.gnu.org/licenses/>. |
205 | + |
206 | +"""Base tests cases and test utilities.""" |
207 | + |
208 | +from __future__ import absolute_import, with_statement |
209 | + |
210 | +import os |
211 | + |
212 | +from twisted.internet import defer |
213 | + |
214 | +# lint seems not tow work well when we use decorators |
215 | +# pylint:disable=W0611 |
216 | +from ubuntuone.devtools.testcase import BaseTestCase, skipIf |
217 | +# pylint:enable=W0611 |
218 | +# DBusRunner for DBusTestCase using tests |
219 | +from ubuntuone.devtools.services.dbus import DBusRunner |
220 | + |
221 | + |
222 | +# pylint: disable=F0401,C0103,W0406,E0611 |
223 | +try: |
224 | + import dbus |
225 | +except ImportError, e: |
226 | + dbus = None |
227 | + |
228 | +try: |
229 | + import dbus.service as service |
230 | +except ImportError: |
231 | + service = None |
232 | + |
233 | +try: |
234 | + from dbus.mainloop.glib import DBusGMainLoop |
235 | +except ImportError: |
236 | + DBusGMainLoop = None |
237 | + |
238 | +# pylint: enable=F0401,C0103,W0406,E0611 |
239 | + |
240 | + |
241 | +class InvalidSessionBus(Exception): |
242 | + """Error when we are connected to the wrong session bus in tests.""" |
243 | + |
244 | + |
245 | +class FakeDBusInterface(object): |
246 | + """A fake DBusInterface...""" |
247 | + |
248 | + def shutdown(self, with_restart=False): |
249 | + """...that only knows how to go away""" |
250 | + |
251 | + |
252 | +@skipIf(dbus is None or service is None or DBusGMainLoop is None, |
253 | + "The test requires dbus.") |
254 | +class DBusTestCase(BaseTestCase): |
255 | + """Test the DBus event handling.""" |
256 | + |
257 | + def required_services(self): |
258 | + """Return the list of required services for DBusTestCase.""" |
259 | + services = super(DBusTestCase, self).required_services() |
260 | + services.extend([DBusRunner]) |
261 | + return services |
262 | + |
263 | + @defer.inlineCallbacks |
264 | + def setUp(self): |
265 | + """Setup the infrastructure fo the test (dbus service).""" |
266 | + # Class 'BaseTestCase' has no 'setUp' member |
267 | + # pylint: disable=E1101 |
268 | + # dbus modules will be imported by the decorator |
269 | + # pylint: disable=E0602 |
270 | + yield super(DBusTestCase, self).setUp() |
271 | + |
272 | + # We need to ensure DBUS_SESSION_BUS_ADDRESS is private here |
273 | + from urllib import unquote |
274 | + bus_address = os.environ.get('DBUS_SESSION_BUS_ADDRESS', None) |
275 | + if os.path.dirname(unquote(bus_address.split(',')[0].split('=')[1])) \ |
276 | + != os.path.dirname(os.getcwd()): |
277 | + raise InvalidSessionBus('DBUS_SESSION_BUS_ADDRES is wrong.') |
278 | + |
279 | + # Set up the main loop and bus connection |
280 | + self.loop = DBusGMainLoop(set_as_default=True) |
281 | + self.bus = dbus.bus.BusConnection(address_or_type=bus_address, |
282 | + mainloop=self.loop) |
283 | + |
284 | + # Monkeypatch the dbus.SessionBus/SystemBus methods, to ensure we |
285 | + # always point at our own private bus instance. |
286 | + self.patch(dbus, 'SessionBus', lambda: self.bus) |
287 | + self.patch(dbus, 'SystemBus', lambda: self.bus) |
288 | + |
289 | + # Check that we are on the correct bus for real |
290 | +# Disable this for now, because our tests are extremely broken :( |
291 | +# bus_names = self.bus.list_names() |
292 | +# if len(bus_names) > 2: |
293 | +# raise InvalidSessionBus('Too many bus connections: %s (%r)' % |
294 | +# (len(bus_names), bus_names)) |
295 | + |
296 | + # monkeypatch busName.__del__ to avoid errors on gc |
297 | + # we take care of releasing the name in shutdown |
298 | + service.BusName.__del__ = lambda _: None |
299 | + yield self.bus.set_exit_on_disconnect(False) |
300 | + self.signal_receivers = set() |
301 | + |
302 | + @defer.inlineCallbacks |
303 | + def tearDown(self): |
304 | + """Cleanup the test.""" |
305 | + yield self.bus.flush() |
306 | + yield self.bus.close() |
307 | + yield super(DBusTestCase, self).tearDown() |
308 | |
309 | === modified file 'ubuntuone/devtools/testing/txcheck.py' |
310 | --- ubuntuone/devtools/testing/txcheck.py 2011-11-03 11:50:48 +0000 |
311 | +++ ubuntuone/devtools/testing/txcheck.py 2011-11-23 11:17:24 +0000 |
312 | @@ -330,7 +330,7 @@ |
313 | class TXCheckTest(TestCase): |
314 | """Test case which checks the test classes for problems.""" |
315 | |
316 | - def runTest(self): # pylint: disable-msg=C0103 |
317 | + def runTest(self): # pylint: disable=C0103 |
318 | """Do nothing.""" |
319 | |
320 | def run(self, result=None): |
+1