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
=== modified file 'bin/u1lint'
--- bin/u1lint 2012-03-30 17:44:03 +0000
+++ bin/u1lint 2012-06-26 20:46:38 +0000
@@ -1,8 +1,4 @@
1#!/usr/bin/python1#!/usr/bin/python
2
3# u1lint: Wrapper script for pylint or pyflakes
4#
5# Author: Rodney Dawes <rodney.dawes@canonical.com>
6#2#
7# Copyright 2009-2012 Canonical Ltd.3# Copyright 2009-2012 Canonical Ltd.
8#4#
@@ -147,7 +143,7 @@
147 config.read([PYLINTRC])143 config.read([PYLINTRC])
148144
149 # pylint: disable=E1103145 # pylint: disable=E1103
150 return [os.path.join(SRCDIR, item) for item in \146 return [os.path.join(SRCDIR, item) for item in
151 config.get("MASTER", "ignore").split(",")]147 config.get("MASTER", "ignore").split(",")]
152 except (TypeError, ConfigParser.NoOptionError):148 except (TypeError, ConfigParser.NoOptionError):
153 return []149 return []
@@ -217,7 +213,7 @@
217 failed = False213 failed = False
218 ignored = _read_pylintrc_ignored()214 ignored = _read_pylintrc_ignored()
219 if options.ignored:215 if options.ignored:
220 ignored.extend([os.path.join(SRCDIR, item) for item in \216 ignored.extend([os.path.join(SRCDIR, item) for item in
221 map(str.strip, options.ignored.split(','))])217 map(str.strip, options.ignored.split(','))])
222218
223 if os.environ.get('USE_PYFLAKES'):219 if os.environ.get('USE_PYFLAKES'):
224220
=== modified file 'bin/u1trial'
--- bin/u1trial 2012-04-25 20:11:12 +0000
+++ bin/u1trial 2012-06-26 20:46:38 +0000
@@ -1,8 +1,4 @@
1#!/usr/bin/env python1#!/usr/bin/python
2
3# u1trial: Test runner for Python unit tests needing DBus
4#
5# Author: Rodney Dawes <rodney.dawes@canonical.com>
6#2#
7# Copyright 2009-2012 Canonical Ltd.3# Copyright 2009-2012 Canonical Ltd.
8#4#
@@ -224,6 +220,14 @@
224 return result220 return result
225221
226222
223def _get_default_reactor():
224 """Return the platform-dependent default reactor to use."""
225 default_reactor = 'gi'
226 if sys.platform in ['darwin', 'win32']:
227 default_reactor = 'twisted'
228 return default_reactor
229
230
227class Options(trial.Options):231class Options(trial.Options):
228 """Class for options handling."""232 """Class for options handling."""
229233
@@ -236,7 +240,7 @@
236 ["loop", None, 1],240 ["loop", None, 1],
237 ["ignore-modules", "i", ""],241 ["ignore-modules", "i", ""],
238 ["ignore-paths", "p", ""],242 ["ignore-paths", "p", ""],
239 ["reactor", "r", "gi"],243 ["reactor", "r", _get_default_reactor()],
240 ]244 ]
241245
242 def __init__(self):246 def __init__(self):
243247
=== modified file 'run-tests'
--- run-tests 2012-04-24 16:37:39 +0000
+++ run-tests 2012-06-26 20:46:38 +0000
@@ -1,7 +1,6 @@
1#!/bin/bash1#!/bin/bash
2# Author: Natalia Bidart <natalia.bidart@canonical.com>
3#2#
4# Copyright 2010-2011 Canonical Ltd.3# Copyright 2010-2012 Canonical Ltd.
5#4#
6# This program is free software: you can redistribute it and/or modify it5# This program is free software: you can redistribute it and/or modify it
7# 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
@@ -16,10 +15,12 @@
16# with this program. If not, see <http://www.gnu.org/licenses/>.15# with this program. If not, see <http://www.gnu.org/licenses/>.
17set -e16set -e
1817
19bin/u1trial -i "test_squid_windows.py" -c ubuntuone18PYTHON="python"
20bin/u1trial --reactor=twisted -i "test_squid_windows.py" ubuntuone19
20$PYTHON bin/u1trial -i "test_squid_windows.py" -c ubuntuone
21$PYTHON bin/u1trial --reactor=twisted -i "test_squid_windows.py" ubuntuone
21echo "Running style checks..."22echo "Running style checks..."
22bin/u1lint23$PYTHON bin/u1lint
23pep8 --repeat . bin/* --exclude=*.bat24pep8 --repeat . bin/* --exclude=*.bat
24rm -rf _trial_temp25rm -rf _trial_temp
25rm -rf .coverage26rm -rf .coverage
2627
=== modified file 'run-tests.bat'
--- run-tests.bat 2012-04-30 11:03:04 +0000
+++ run-tests.bat 2012-06-26 20:46:38 +0000
@@ -29,12 +29,11 @@
29@ECHO off29@ECHO off
3030
31SET IGNORED="test_squid_linux.py"31SET IGNORED="test_squid_linux.py"
32SET LINTIGNORED="ubuntuone\devtools\services\dbus.py,ubuntuone\devtools\services\tests\test_squid_linux.py"
3233
33ECHO Checking for Python on the path34ECHO Checking for Python on the path
34:: Look for Python from buildout35:: Look for Python from buildout
35FOR %%A in (python.exe) do (SET PYTHONEXEPATH=%%~$PATH:A)36FOR %%A in (python.exe) do (SET PYTHONEXEPATH=%%~$PATH:A)
36FOR %%B in (u1trial) do (SET TRIALPATH=%%~$PATH:B)
37FOR %%C in (u1lint) do (SET LINTPATH=%%~$PATH:C)
38FOR %%D in (pep8.exe) do (SET PEP8PATH=%%~$PATH:D)37FOR %%D in (pep8.exe) do (SET PEP8PATH=%%~$PATH:D)
3938
40IF NOT "%PYTHONEXEPATH%" == "" GOTO :PYTHONPRESENT39IF NOT "%PYTHONEXEPATH%" == "" GOTO :PYTHONPRESENT
@@ -69,16 +68,16 @@
6968
70ECHO Python found at %PYTHONEXEPATH%, executing the tests...69ECHO Python found at %PYTHONEXEPATH%, executing the tests...
71:: execute the tests with a number of ignored linux only modules70:: execute the tests with a number of ignored linux only modules
72"%PYTHONEXEPATH%" bin/u1trial --reactor=twisted -i %IGNORED% -c %PARAMS% ubuntuone71"%PYTHONEXEPATH%" bin/u1trial -i %IGNORED% -c %PARAMS% ubuntuone
7372
74IF %SKIPLINT% == 1 (73IF %SKIPLINT% == 1 (
75 ECHO Skipping style checks74 ECHO Skipping style checks
76 GOTO :CLEAN)75 GOTO :CLEAN)
7776
78"%PYTHONEXEPATH%" "%LINTPATH%" 77"%PYTHONEXEPATH%" bin/u1lint -i %LINTIGNORED%
79:: test for style if we can, if pep8 is not present, move to the end78:: test for style if we can, if pep8 is not present, move to the end
80IF NOT EXIST "%PEP8PATH%" GOTO :NOPEP879IF NOT EXIST "%PEP8PATH%" GOTO :NOPEP8
81START "Pep8" /B "%PEP8PATH%" --repeat80START "Pep8" /B "%PEP8PATH%" --repeat .
82:NOPEP881:NOPEP8
83ECHO Style checks were not done82ECHO Style checks were not done
84:CLEAN83:CLEAN
8584
=== modified file 'setup.py'
--- setup.py 2012-06-05 17:05:51 +0000
+++ setup.py 2012-06-26 20:46:38 +0000
@@ -1,4 +1,4 @@
1#!/usr/bin/env python1#!/usr/bin/python
2#2#
3# Copyright 2010-2012 Canonical Ltd.3# Copyright 2010-2012 Canonical Ltd.
4#4#
55
=== modified file 'ubuntuone/devtools/services/squid.py'
--- ubuntuone/devtools/services/squid.py 2012-04-26 14:52:43 +0000
+++ ubuntuone/devtools/services/squid.py 2012-06-26 20:46:38 +0000
@@ -113,7 +113,9 @@
113 win32api.TerminateProcess(handle, 0)113 win32api.TerminateProcess(handle, 0)
114 win32api.CloseHandle(handle)114 win32api.CloseHandle(handle)
115 else:115 else:
116 # pylint: disable=E1101
116 kill(squid_pid, signal.SIGKILL)117 kill(squid_pid, signal.SIGKILL)
118 # pylint: enable=E1101
117119
118120
119def _make_random_string(count):121def _make_random_string(count):
120122
=== modified file 'ubuntuone/devtools/testcases/__init__.py'
--- ubuntuone/devtools/testcases/__init__.py 2012-05-14 14:29:25 +0000
+++ ubuntuone/devtools/testcases/__init__.py 2012-06-26 20:46:38 +0000
@@ -63,7 +63,7 @@
6363
64 def decorator(test_item):64 def decorator(test_item):
65 """Decorate the test so that it is skipped."""65 """Decorate the test so that it is skipped."""
66 if not (isinstance(test_item, type) and\66 if not (isinstance(test_item, type) and
67 issubclass(test_item, TestCase)):67 issubclass(test_item, TestCase)):
6868
69 @wraps(test_item)69 @wraps(test_item)
7070
=== modified file 'ubuntuone/devtools/testcases/tests/test_txsocketserver.py'
--- ubuntuone/devtools/testcases/tests/test_txsocketserver.py 2012-04-26 14:16:33 +0000
+++ ubuntuone/devtools/testcases/tests/test_txsocketserver.py 2012-06-26 20:46:38 +0000
@@ -289,7 +289,7 @@
289 def test_deferreds(self):289 def test_deferreds(self):
290 """Test that the deferreds are not broken."""290 """Test that the deferreds are not broken."""
291 self.assertFalse(self.client_disconnected.called)291 self.assertFalse(self.client_disconnected.called)
292 self.assertFalse(self.server_disconnected.called)292 self.assertEqual(None, self.server_disconnected)
293293
294 @defer.inlineCallbacks294 @defer.inlineCallbacks
295 def test_addition(self):295 def test_addition(self):
296296
=== modified file 'ubuntuone/devtools/testcases/txsocketserver.py'
--- ubuntuone/devtools/testcases/txsocketserver.py 2012-05-22 14:19:19 +0000
+++ ubuntuone/devtools/testcases/txsocketserver.py 2012-06-26 20:46:38 +0000
@@ -37,7 +37,7 @@
3737
38from ubuntuone.devtools.testcases import BaseTestCase38from ubuntuone.devtools.testcases import BaseTestCase
3939
40# no init method + twisted common warnings40# no init method + twisted common warnings
41# pylint: disable=W0232, C0103, E110141# pylint: disable=W0232, C0103, E1101
4242
4343
@@ -64,6 +64,25 @@
64 return ServerTidyProtocol64 return ServerTidyProtocol
6565
6666
67def server_factory_factory(cls):
68 """Factory that creates special types of factories for tests."""
69
70 if cls is None:
71 cls = protocol.ServerFactory
72
73 class TidyServerFactory(cls):
74 """A tidy factory."""
75
76 testserver_on_connection_lost = None
77
78 def buildProtocol(self, addr):
79 prot = cls.buildProtocol(self, addr)
80 self.testserver_on_connection_lost = defer.Deferred()
81 return prot
82
83 return TidyServerFactory
84
85
67def client_protocol_factory(cls):86def client_protocol_factory(cls):
68 """Factory to create tidy protocols."""87 """Factory to create tidy protocols."""
6988
@@ -75,13 +94,13 @@
7594
76 def connectionLost(self, *a):95 def connectionLost(self, *a):
77 """Connection list."""96 """Connection list."""
78 # pylint: disable=W0212
79 if (self.factory._disconnecting
80 and self.factory.testserver_on_connection_lost is not None
81 and not self.factory.testserver_on_connection_lost.called):
82 self.factory.testserver_on_connection_lost.callback(self)
83 # pylint: enable=W0212
84 cls.connectionLost(self, *a)97 cls.connectionLost(self, *a)
98 # pylint: disable=W0212
99 if (self.factory._disconnecting
100 and self.factory.testserver_on_connection_lost is not None
101 and not self.factory.testserver_on_connection_lost.called):
102 self.factory.testserver_on_connection_lost.callback(self)
103 # pylint: enable=W0212
85104
86 return ClientTidyProtocol105 return ClientTidyProtocol
87106
@@ -120,9 +139,9 @@
120 def listen_server(self, server_class, *args, **kwargs):139 def listen_server(self, server_class, *args, **kwargs):
121 """Start a server in a random port."""140 """Start a server in a random port."""
122 from twisted.internet import reactor141 from twisted.internet import reactor
123 self.server_factory = server_class(*args, **kwargs)142 tidy_class = server_factory_factory(server_class)
143 self.server_factory = tidy_class(*args, **kwargs)
124 self.server_factory._disconnecting = False144 self.server_factory._disconnecting = False
125 self.server_factory.testserver_on_connection_lost = defer.Deferred()
126 self.server_factory.protocol = server_protocol_factory(145 self.server_factory.protocol = server_protocol_factory(
127 self.server_factory.protocol)146 self.server_factory.protocol)
128 endpoint = endpoints.serverFromString(reactor,147 endpoint = endpoints.serverFromString(reactor,
@@ -161,15 +180,21 @@
161 # clean client and server180 # clean client and server
162 self.server_factory._disconnecting = True181 self.server_factory._disconnecting = True
163 self.client_factory._disconnecting = True182 self.client_factory._disconnecting = True
183 d = defer.maybeDeferred(self.listener.stopListening)
164 self.connector.transport.loseConnection()184 self.connector.transport.loseConnection()
165 d = defer.maybeDeferred(self.listener.stopListening)185 if self.server_factory.testserver_on_connection_lost:
166 return defer.gatherResults([d,186 return defer.gatherResults([d,
167 self.client_factory.testserver_on_connection_lost,187 self.client_factory.testserver_on_connection_lost,
168 self.server_factory.testserver_on_connection_lost])188 self.server_factory.testserver_on_connection_lost])
189 else:
190 return defer.gatherResults([d,
191 self.client_factory.testserver_on_connection_lost])
169 if self.listener:192 if self.listener:
170 # just clean the server since there is no client193 # just clean the server since there is no client
194 # pylint: disable=W0201
171 self.server_factory._disconnecting = True195 self.server_factory._disconnecting = True
172 return defer.maybeDeferred(self.listener.stopListening)196 return defer.maybeDeferred(self.listener.stopListening)
197 # pylint: enable=W0201
173198
174199
175class TidyTCPServer(TidySocketServer):200class TidyTCPServer(TidySocketServer):

Subscribers

People subscribed via source and target branches

to all changes: