Merge lp:~dobey/ubuntuone-dev-tools/update-4-0 into lp:ubuntuone-dev-tools/stable-4-0

Proposed by dobey
Status: Merged
Approved by: Mike McCracken
Approved revision: no longer in the source branch.
Merged at revision: 75
Proposed branch: lp:~dobey/ubuntuone-dev-tools/update-4-0
Merge into: lp:ubuntuone-dev-tools/stable-4-0
Diff against target: 282 lines (+65/-38)
9 files modified
bin/u1lint (+2/-6)
bin/u1trial (+10/-6)
run-tests (+6/-5)
run-tests.bat (+4/-5)
setup.py (+1/-1)
ubuntuone/devtools/services/squid.py (+2/-0)
ubuntuone/devtools/testcases/__init__.py (+1/-1)
ubuntuone/devtools/testcases/tests/test_txsocketserver.py (+1/-1)
ubuntuone/devtools/testcases/txsocketserver.py (+38/-13)
To merge this branch: bzr merge lp:~dobey/ubuntuone-dev-tools/update-4-0
Reviewer Review Type Date Requested Status
Mike McCracken (community) Approve
Eric Casteleijn (community) Approve
Review via email: mp+112217@code.launchpad.net

Commit message

[Manuel de la Pena]

    Ensure that we only wait for the deferred when a protocol was created server side (LP: #1009408).

[Rodney Dawes]

    Define a method to get the platform-dependent default reactor and use it.
    Avoid using /usr/bin/env python in scripts.

To post a comment you must log in.
Revision history for this message
Eric Casteleijn (thisfred) wrote :

looks ok to me

review: Approve
Revision history for this message
Mike McCracken (mikemc) wrote :

agreed

review: Approve
75. By Manuel de la Peña

[Manuel de la Pena]

    Ensure that we only wait for the deferred when a protocol was created server side (LP: #1009408).

[Rodney Dawes]

    Define a method to get the platform-dependent default reactor and use it.
    Avoid using /usr/bin/env python in scripts.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/u1lint'
2--- bin/u1lint 2012-03-30 17:44:03 +0000
3+++ bin/u1lint 2012-06-26 20:46:38 +0000
4@@ -1,8 +1,4 @@
5 #!/usr/bin/python
6-
7-# u1lint: Wrapper script for pylint or pyflakes
8-#
9-# Author: Rodney Dawes <rodney.dawes@canonical.com>
10 #
11 # Copyright 2009-2012 Canonical Ltd.
12 #
13@@ -147,7 +143,7 @@
14 config.read([PYLINTRC])
15
16 # pylint: disable=E1103
17- return [os.path.join(SRCDIR, item) for item in \
18+ return [os.path.join(SRCDIR, item) for item in
19 config.get("MASTER", "ignore").split(",")]
20 except (TypeError, ConfigParser.NoOptionError):
21 return []
22@@ -217,7 +213,7 @@
23 failed = False
24 ignored = _read_pylintrc_ignored()
25 if options.ignored:
26- ignored.extend([os.path.join(SRCDIR, item) for item in \
27+ ignored.extend([os.path.join(SRCDIR, item) for item in
28 map(str.strip, options.ignored.split(','))])
29
30 if os.environ.get('USE_PYFLAKES'):
31
32=== modified file 'bin/u1trial'
33--- bin/u1trial 2012-04-25 20:11:12 +0000
34+++ bin/u1trial 2012-06-26 20:46:38 +0000
35@@ -1,8 +1,4 @@
36-#!/usr/bin/env python
37-
38-# u1trial: Test runner for Python unit tests needing DBus
39-#
40-# Author: Rodney Dawes <rodney.dawes@canonical.com>
41+#!/usr/bin/python
42 #
43 # Copyright 2009-2012 Canonical Ltd.
44 #
45@@ -224,6 +220,14 @@
46 return result
47
48
49+def _get_default_reactor():
50+ """Return the platform-dependent default reactor to use."""
51+ default_reactor = 'gi'
52+ if sys.platform in ['darwin', 'win32']:
53+ default_reactor = 'twisted'
54+ return default_reactor
55+
56+
57 class Options(trial.Options):
58 """Class for options handling."""
59
60@@ -236,7 +240,7 @@
61 ["loop", None, 1],
62 ["ignore-modules", "i", ""],
63 ["ignore-paths", "p", ""],
64- ["reactor", "r", "gi"],
65+ ["reactor", "r", _get_default_reactor()],
66 ]
67
68 def __init__(self):
69
70=== modified file 'run-tests'
71--- run-tests 2012-04-24 16:37:39 +0000
72+++ run-tests 2012-06-26 20:46:38 +0000
73@@ -1,7 +1,6 @@
74 #!/bin/bash
75-# Author: Natalia Bidart <natalia.bidart@canonical.com>
76 #
77-# Copyright 2010-2011 Canonical Ltd.
78+# Copyright 2010-2012 Canonical Ltd.
79 #
80 # This program is free software: you can redistribute it and/or modify it
81 # under the terms of the GNU General Public License version 3, as published
82@@ -16,10 +15,12 @@
83 # with this program. If not, see <http://www.gnu.org/licenses/>.
84 set -e
85
86-bin/u1trial -i "test_squid_windows.py" -c ubuntuone
87-bin/u1trial --reactor=twisted -i "test_squid_windows.py" ubuntuone
88+PYTHON="python"
89+
90+$PYTHON bin/u1trial -i "test_squid_windows.py" -c ubuntuone
91+$PYTHON bin/u1trial --reactor=twisted -i "test_squid_windows.py" ubuntuone
92 echo "Running style checks..."
93-bin/u1lint
94+$PYTHON bin/u1lint
95 pep8 --repeat . bin/* --exclude=*.bat
96 rm -rf _trial_temp
97 rm -rf .coverage
98
99=== modified file 'run-tests.bat'
100--- run-tests.bat 2012-04-30 11:03:04 +0000
101+++ run-tests.bat 2012-06-26 20:46:38 +0000
102@@ -29,12 +29,11 @@
103 @ECHO off
104
105 SET IGNORED="test_squid_linux.py"
106+SET LINTIGNORED="ubuntuone\devtools\services\dbus.py,ubuntuone\devtools\services\tests\test_squid_linux.py"
107
108 ECHO Checking for Python on the path
109 :: Look for Python from buildout
110 FOR %%A in (python.exe) do (SET PYTHONEXEPATH=%%~$PATH:A)
111-FOR %%B in (u1trial) do (SET TRIALPATH=%%~$PATH:B)
112-FOR %%C in (u1lint) do (SET LINTPATH=%%~$PATH:C)
113 FOR %%D in (pep8.exe) do (SET PEP8PATH=%%~$PATH:D)
114
115 IF NOT "%PYTHONEXEPATH%" == "" GOTO :PYTHONPRESENT
116@@ -69,16 +68,16 @@
117
118 ECHO Python found at %PYTHONEXEPATH%, executing the tests...
119 :: execute the tests with a number of ignored linux only modules
120-"%PYTHONEXEPATH%" bin/u1trial --reactor=twisted -i %IGNORED% -c %PARAMS% ubuntuone
121+"%PYTHONEXEPATH%" bin/u1trial -i %IGNORED% -c %PARAMS% ubuntuone
122
123 IF %SKIPLINT% == 1 (
124 ECHO Skipping style checks
125 GOTO :CLEAN)
126
127-"%PYTHONEXEPATH%" "%LINTPATH%"
128+"%PYTHONEXEPATH%" bin/u1lint -i %LINTIGNORED%
129 :: test for style if we can, if pep8 is not present, move to the end
130 IF NOT EXIST "%PEP8PATH%" GOTO :NOPEP8
131-START "Pep8" /B "%PEP8PATH%" --repeat
132+START "Pep8" /B "%PEP8PATH%" --repeat .
133 :NOPEP8
134 ECHO Style checks were not done
135 :CLEAN
136
137=== modified file 'setup.py'
138--- setup.py 2012-06-05 17:05:51 +0000
139+++ setup.py 2012-06-26 20:46:38 +0000
140@@ -1,4 +1,4 @@
141-#!/usr/bin/env python
142+#!/usr/bin/python
143 #
144 # Copyright 2010-2012 Canonical Ltd.
145 #
146
147=== modified file 'ubuntuone/devtools/services/squid.py'
148--- ubuntuone/devtools/services/squid.py 2012-04-26 14:52:43 +0000
149+++ ubuntuone/devtools/services/squid.py 2012-06-26 20:46:38 +0000
150@@ -113,7 +113,9 @@
151 win32api.TerminateProcess(handle, 0)
152 win32api.CloseHandle(handle)
153 else:
154+ # pylint: disable=E1101
155 kill(squid_pid, signal.SIGKILL)
156+ # pylint: enable=E1101
157
158
159 def _make_random_string(count):
160
161=== modified file 'ubuntuone/devtools/testcases/__init__.py'
162--- ubuntuone/devtools/testcases/__init__.py 2012-05-14 14:29:25 +0000
163+++ ubuntuone/devtools/testcases/__init__.py 2012-06-26 20:46:38 +0000
164@@ -63,7 +63,7 @@
165
166 def decorator(test_item):
167 """Decorate the test so that it is skipped."""
168- if not (isinstance(test_item, type) and\
169+ if not (isinstance(test_item, type) and
170 issubclass(test_item, TestCase)):
171
172 @wraps(test_item)
173
174=== modified file 'ubuntuone/devtools/testcases/tests/test_txsocketserver.py'
175--- ubuntuone/devtools/testcases/tests/test_txsocketserver.py 2012-04-26 14:16:33 +0000
176+++ ubuntuone/devtools/testcases/tests/test_txsocketserver.py 2012-06-26 20:46:38 +0000
177@@ -289,7 +289,7 @@
178 def test_deferreds(self):
179 """Test that the deferreds are not broken."""
180 self.assertFalse(self.client_disconnected.called)
181- self.assertFalse(self.server_disconnected.called)
182+ self.assertEqual(None, self.server_disconnected)
183
184 @defer.inlineCallbacks
185 def test_addition(self):
186
187=== modified file 'ubuntuone/devtools/testcases/txsocketserver.py'
188--- ubuntuone/devtools/testcases/txsocketserver.py 2012-05-22 14:19:19 +0000
189+++ ubuntuone/devtools/testcases/txsocketserver.py 2012-06-26 20:46:38 +0000
190@@ -37,7 +37,7 @@
191
192 from ubuntuone.devtools.testcases import BaseTestCase
193
194-# no init method + twisted common warnings
195+# no init method + twisted common warnings
196 # pylint: disable=W0232, C0103, E1101
197
198
199@@ -64,6 +64,25 @@
200 return ServerTidyProtocol
201
202
203+def server_factory_factory(cls):
204+ """Factory that creates special types of factories for tests."""
205+
206+ if cls is None:
207+ cls = protocol.ServerFactory
208+
209+ class TidyServerFactory(cls):
210+ """A tidy factory."""
211+
212+ testserver_on_connection_lost = None
213+
214+ def buildProtocol(self, addr):
215+ prot = cls.buildProtocol(self, addr)
216+ self.testserver_on_connection_lost = defer.Deferred()
217+ return prot
218+
219+ return TidyServerFactory
220+
221+
222 def client_protocol_factory(cls):
223 """Factory to create tidy protocols."""
224
225@@ -75,13 +94,13 @@
226
227 def connectionLost(self, *a):
228 """Connection list."""
229- # pylint: disable=W0212
230- if (self.factory._disconnecting
231- and self.factory.testserver_on_connection_lost is not None
232- and not self.factory.testserver_on_connection_lost.called):
233- self.factory.testserver_on_connection_lost.callback(self)
234- # pylint: enable=W0212
235 cls.connectionLost(self, *a)
236+ # pylint: disable=W0212
237+ if (self.factory._disconnecting
238+ and self.factory.testserver_on_connection_lost is not None
239+ and not self.factory.testserver_on_connection_lost.called):
240+ self.factory.testserver_on_connection_lost.callback(self)
241+ # pylint: enable=W0212
242
243 return ClientTidyProtocol
244
245@@ -120,9 +139,9 @@
246 def listen_server(self, server_class, *args, **kwargs):
247 """Start a server in a random port."""
248 from twisted.internet import reactor
249- self.server_factory = server_class(*args, **kwargs)
250+ tidy_class = server_factory_factory(server_class)
251+ self.server_factory = tidy_class(*args, **kwargs)
252 self.server_factory._disconnecting = False
253- self.server_factory.testserver_on_connection_lost = defer.Deferred()
254 self.server_factory.protocol = server_protocol_factory(
255 self.server_factory.protocol)
256 endpoint = endpoints.serverFromString(reactor,
257@@ -161,15 +180,21 @@
258 # clean client and server
259 self.server_factory._disconnecting = True
260 self.client_factory._disconnecting = True
261+ d = defer.maybeDeferred(self.listener.stopListening)
262 self.connector.transport.loseConnection()
263- d = defer.maybeDeferred(self.listener.stopListening)
264- return defer.gatherResults([d,
265- self.client_factory.testserver_on_connection_lost,
266- self.server_factory.testserver_on_connection_lost])
267+ if self.server_factory.testserver_on_connection_lost:
268+ return defer.gatherResults([d,
269+ self.client_factory.testserver_on_connection_lost,
270+ self.server_factory.testserver_on_connection_lost])
271+ else:
272+ return defer.gatherResults([d,
273+ self.client_factory.testserver_on_connection_lost])
274 if self.listener:
275 # just clean the server since there is no client
276+ # pylint: disable=W0201
277 self.server_factory._disconnecting = True
278 return defer.maybeDeferred(self.listener.stopListening)
279+ # pylint: enable=W0201
280
281
282 class TidyTCPServer(TidySocketServer):

Subscribers

People subscribed via source and target branches

to all changes: