[Zope3-checkins] SVN: Zope3/trunk/ Update the version of Twisted to
2.5
Michael Kerrin
michael.kerrin at openapp.biz
Thu Feb 1 16:39:05 EST 2007
Log message for revision 72310:
Update the version of Twisted to 2.5
Changed:
U Zope3/trunk/doc/CHANGES.txt
_U Zope3/trunk/src/
U Zope3/trunk/src/zope/app/twisted/ftp/tests/test_zope_ftp.py
U Zope3/trunk/src/zope/app/twisted/ftp/tests/test_zopetrial.py
U Zope3/trunk/src/zope/app/twisted/ftp/tests/trial.txt
U Zope3/trunk/src/zope/app/twisted/ftp/tests/trialtest.py
U Zope3/trunk/src/zope/app/twisted/ftp/tests/trialtestfs.py
U Zope3/trunk/src/zope/app/twisted/ftp/tests/trialtestft.py
U Zope3/trunk/src/zope/app/twisted/http.py
U Zope3/trunk/src/zope/app/twisted/log.txt
U Zope3/trunk/src/zope/app/twisted/tests/test_inputbuffering.py
A Zope3/trunk/src/zope/app/twisted/tests/test_largeinput.py
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2007-02-01 21:20:27 UTC (rev 72309)
+++ Zope3/trunk/doc/CHANGES.txt 2007-02-01 21:39:01 UTC (rev 72310)
@@ -99,6 +99,8 @@
Restructuring
+ - Updated the version of Twisted to 2.5
+
- Implemented "Loading Configuration from the zope.app Egg" proposal.
Now zope.app is a namespace package. ZCML files in zope.app package
is moved to zope.app.zcmlfiles (a new package with only ZCML files).
Property changes on: Zope3/trunk/src
___________________________________________________________________
Name: svn:externals
- docutils svn://svn.zope.org/repos/main/docutils/tags/0.4.0
ZConfig svn://svn.zope.org/repos/main/ZConfig/trunk/ZConfig
BTrees -r 71248 svn://svn.zope.org/repos/main/ZODB/branches/3.7/src/BTrees
persistent -r 71248 svn://svn.zope.org/repos/main/ZODB/branches/3.7/src/persistent
ThreadedAsync -r 71248 svn://svn.zope.org/repos/main/ZODB/branches/3.7/src/ThreadedAsync
transaction -r 71248 svn://svn.zope.org/repos/main/ZODB/branches/3.7/src/transaction
ZEO -r 71248 svn://svn.zope.org/repos/main/ZODB/branches/3.7/src/ZEO
ZODB -r 71248 svn://svn.zope.org/repos/main/ZODB/branches/3.7/src/ZODB
twisted -r 15340 svn://svn.twistedmatrix.com/svn/Twisted/branches/releases/2.1.x/twisted
zdaemon -r 40792 svn://svn.zope.org/repos/main/zdaemon/trunk/src/zdaemon
+ docutils svn://svn.zope.org/repos/main/docutils/tags/0.4.0
ZConfig svn://svn.zope.org/repos/main/ZConfig/trunk/ZConfig
BTrees -r 71248 svn://svn.zope.org/repos/main/ZODB/branches/3.7/src/BTrees
persistent -r 71248 svn://svn.zope.org/repos/main/ZODB/branches/3.7/src/persistent
ThreadedAsync -r 71248 svn://svn.zope.org/repos/main/ZODB/branches/3.7/src/ThreadedAsync
transaction -r 71248 svn://svn.zope.org/repos/main/ZODB/branches/3.7/src/transaction
ZEO -r 71248 svn://svn.zope.org/repos/main/ZODB/branches/3.7/src/ZEO
ZODB -r 71248 svn://svn.zope.org/repos/main/ZODB/branches/3.7/src/ZODB
twisted svn://svn.twistedmatrix.com/svn/Twisted/tags/releases/twisted-core-2.5.0/twisted
zdaemon -r 40792 svn://svn.zope.org/repos/main/zdaemon/trunk/src/zdaemon
Modified: Zope3/trunk/src/zope/app/twisted/ftp/tests/test_zope_ftp.py
===================================================================
--- Zope3/trunk/src/zope/app/twisted/ftp/tests/test_zope_ftp.py 2007-02-01 21:20:27 UTC (rev 72309)
+++ Zope3/trunk/src/zope/app/twisted/ftp/tests/test_zope_ftp.py 2007-02-01 21:39:01 UTC (rev 72310)
@@ -29,16 +29,11 @@
from zope.app.twisted.ftp.tests.test_publisher import RequestFactory
from zope.app.twisted.ftp.tests import demofs
-from twisted.trial.util import wait
from twisted.trial.unittest import TestCase
-## Install monkey patches in the test_zopetrail module that
-## allow me to cleanly test the Twisted server code from within
-## the Zope test runner.
-import test_zopetrial
+class DemoFileSystem(demofs.DemoFileSystem):
-class DemoFileSystem(demofs.DemoFileSystem):
def mkdir_nocheck(self, path):
path, name = posixpath.split(path)
d = self.getdir(path)
@@ -65,11 +60,16 @@
else:
f.data = instream.read()
+
class FTPServerTestCase(test_ftp.FTPServerTestCase):
+
def tearDown(self):
- ## Uninstall the monkey patches needed to get the tiral tests
- ## running successfully within the zope test runner.
- test_zopetrial.killthreads()
+ # Twisted trial has a habit of leaving threads lying about when run
+ # from within the Zope test runner - do_cleanThreads removes them.
+ # The threads don't actaully cause any errors - they just print
+ # out a few extra lines of information when running the tests.
+ from twisted.trial import util
+ util._Janitor.do_cleanThreads()
# Clean up sockets
self.client.transport.loseConnection()
@@ -95,192 +95,199 @@
# Hook the server's buildProtocol to make the protocol instance
# accessible to tests.
buildProtocol = self.factory.buildProtocol
+ d1 = defer.Deferred()
def _rememberProtocolInstance(addr):
protocol = buildProtocol(addr)
self.serverProtocol = protocol.wrappedProtocol
+ d1.callback(None)
return protocol
self.factory.buildProtocol = _rememberProtocolInstance
# Connect a client to it
portNum = self.port.getHost().port
clientCreator = protocol.ClientCreator(reactor, ftp.FTPClientBasic)
- self.client = wait(clientCreator.connectTCP("127.0.0.1", portNum))
+ d2 = clientCreator.connectTCP("127.0.0.1", portNum)
+ def gotClient(client):
+ self.client = client
+ d2.addCallback(gotClient)
+ return defer.gatherResults([d1, d2])
def _anonymousLogin(self):
- responseLines = wait(self.client.queueStringCommand('USER anonymous'))
- self.assertEquals(
- ['331 Password required for anonymous.'],
- responseLines
- )
-
- responseLines = wait(self.client.queueStringCommand(
- 'PASS test at twistedmatrix.com')
- )
- self.assertEquals(
+ d = self.assertCommandResponse(
+ 'USER anonymous',
+ ['331 Password required for anonymous.'])
+ return self.assertCommandResponse(
+ 'PASS test at twistedmatrix.com',
['230 User logged in, proceed'],
- responseLines
- )
+ chainDeferred = d)
+
class BasicFTPServerTestCase(FTPServerTestCase,
test_ftp.BasicFTPServerTestCase):
def _authLogin(self):
- responseLines = wait(self.client.queueStringCommand('USER root'))
- self.assertEquals(
- ['331 Password required for root.'],
- responseLines
- )
-
- responseLines = wait(self.client.queueStringCommand(
- 'PASS root')
- )
- self.assertEquals(
+ d = self.assertCommandResponse(
+ 'USER root',
+ ['331 Password required for root.'])
+ return self.assertCommandResponse(
+ 'PASS root',
['230 User logged in, proceed'],
- responseLines
- )
+ chainDeferred = d)
- def testQuit(self):
- # this test is causing we problems. Works on 2.2.X but times out
- # on 2.1.X
- pass
-
def test_MKD(self):
- self._authLogin()
- responseLines = wait(self.client.queueStringCommand('MKD /newdir'))
- self.assertEqual(['257 "/newdir" created'], responseLines)
+ d = self._authLogin()
+ return self.assertCommandResponse(
+ 'MKD /newdir',
+ ['257 "/newdir" created'],
+ chainDeferred = d)
def test_RMD(self):
self.rootfs.mkdir_nocheck('/newdir')
- self._authLogin()
- responseLines = wait(self.client.queueStringCommand('RMD /newdir'))
- self.assertEqual(
- ['250 Requested File Action Completed OK'], responseLines)
+ d = self._authLogin()
+ return self.assertCommandResponse(
+ 'RMD /newdir',
+ ['250 Requested File Action Completed OK'],
+ chainDeferred = d)
def test_DELE(self):
self.rootfs.writefile_nocheck('/file.txt', StringIO('x' * 20))
- self._authLogin()
- responseLines = wait(self.client.queueStringCommand('DELE /file.txt'))
- self.assertEqual(
- ['250 Requested File Action Completed OK'], responseLines)
+ d = self._authLogin()
+ return self.assertCommandResponse(
+ 'DELE /file.txt',
+ ['250 Requested File Action Completed OK'],
+ chainDeferred = d)
def test_SIZE(self):
self.rootfs.writefile_nocheck('/file.txt', StringIO('x' * 20))
+ d = self._anonymousLogin()
+ return self.assertCommandResponse(
+ 'SIZE /file.txt',
+ ['213 20'],
+ chainDeferred = d)
- self._anonymousLogin()
- responseLines = wait(self.client.queueStringCommand('SIZE /file.txt'))
- self.assertEqual(['213 20'], responseLines)
-
def test_SIZE_on_dir(self):
- self._anonymousLogin()
- responseLines = wait(self.client.queueStringCommand('SIZE /'))
- self.assertEqual(['213 0'] , responseLines)
+ d = self._anonymousLogin()
+ return self.assertCommandResponse(
+ 'SIZE /',
+ ['213 0'],
+ chainDeferred = d)
def test_RENAME(self):
data = StringIO('x' * 20)
self.rootfs.writefile('/file.txt', data)
- self._authLogin()
- responseLines = wait(
- self.client.queueStringCommand('RNFR /file.txt'))
- self.assertEqual(
+ d = self._authLogin()
+ d = self.assertCommandResponse(
+ 'RNFR /file.txt',
['350 Requested file action pending further information.'],
- responseLines)
- responseLines = wait(
- self.client.queueStringCommand('RNTO /newfile.txt'))
- self.assertEqual(
- ['250 Requested File Action Completed OK'], responseLines)
+ chainDeferred = d)
+ d = self.assertCommandResponse(
+ 'RNTO /newfile.txt',
+ ['250 Requested File Action Completed OK'],
+ chainDeferred = d)
- file = self.rootfs.get('newfile.txt')
- self.assertEqual(file.data, data.getvalue())
- self.assertEqual(['newfile.txt'], self.rootfs.names('/'))
+ def assertFileStatus(result):
+ file = self.rootfs.get('newfile.txt')
+ self.assertEqual(file.data, data.getvalue())
+ self.assertEqual(['newfile.txt'], self.rootfs.names('/'))
+ d.addCallback(assertFileStatus)
+ return d
+
def test_RENAME_duplicate(self):
data = StringIO('x' * 20)
self.rootfs.writefile('/file.txt', data)
datadest = StringIO('y' * 20)
self.rootfs.writefile('/newfile.txt', datadest)
- self._authLogin()
- responseLines = wait(
- self.client.queueStringCommand('RNFR /file.txt'))
- self.assertEqual(
+ d = self._authLogin()
+ d = self.assertCommandResponse(
+ 'RNFR /file.txt',
['350 Requested file action pending further information.'],
- responseLines)
- deferred = self.client.queueStringCommand('RNTO /newfile.txt')
- responseLines = self._waitForCommandFailure(deferred)
- self.assertEqual(
- ['550 /newfile.txt: Permission denied.'], responseLines)
+ chainDeferred = d)
+ d = self.assertCommandFailed(
+ 'RNTO /newfile.txt',
+ ['550 /newfile.txt: Permission denied.'],
+ chainDeferred = d)
+ return d
def test_RENAME_nosource_file(self):
- self._authLogin()
+ d = self._authLogin()
- responseLines = wait(
- self.client.queueStringCommand('RNFR /file.txt'))
- self.assertEqual(
+ d = self.assertCommandResponse(
+ 'RNFR /file.txt',
['350 Requested file action pending further information.'],
- responseLines)
- deferred = self.client.queueStringCommand('RNTO /newfile.txt')
- responseLines = self._waitForCommandFailure(deferred)
- self.assertEqual(
- ['550 /file.txt: No such file or directory.'], responseLines)
+ chainDeferred = d)
+ d = self.assertCommandFailed(
+ 'RNTO /newfile.txt',
+ ['550 /file.txt: No such file or directory.'],
+ chainDeferred = d)
+ return d
-
class FTPServerPasvDataConnectionTestCase(FTPServerTestCase,
test_ftp.FTPServerPasvDataConnectionTestCase):
- def testLIST(self):
+ def testTwoDirLIST(self):
# Login
- self._anonymousLogin()
+ d = self._anonymousLogin()
- # Download a listing
- downloader = self._makeDataConnection()
- d = self.client.queueStringCommand('LIST')
- wait(defer.gatherResults([d, downloader.d]))
-
- # No files, so the file listing should be empty
- self.assertEqual('', downloader.buffer)
-
# Make some directories
self.rootfs.mkdir_nocheck('/foo')
self.rootfs.mkdir_nocheck('/bar')
- # Download a listing again
- downloader = self._makeDataConnection()
- d = self.client.queueStringCommand('LIST')
- wait(defer.gatherResults([d, downloader.d]))
+ self._download('LIST', chainDeferred = d)
+ def checkDownload(download):
+ # Now we expect 2 lines because there are two files.
+ self.assertEqual(2, len(download[:-2].split('\r\n')))
+ d.addCallback(checkDownload)
- # Now we expect 2 lines because there are two files.
- self.assertEqual(2, len(downloader.buffer[:-2].split('\r\n')))
-
# Download a names-only listing
- downloader = self._makeDataConnection()
- d = self.client.queueStringCommand('NLST ')
- wait(defer.gatherResults([d, downloader.d]))
- filenames = downloader.buffer[:-2].split('\r\n')
- filenames.sort()
- self.assertEqual(['bar', 'foo'], filenames)
+ self._download('NLST ', chainDeferred = d)
+ def checkDownload(download):
+ filenames = download[:-2].split('\r\n')
+ filenames.sort()
+ self.assertEqual(['bar', 'foo'], filenames)
+ d.addCallback(checkDownload)
- # Download a listing of the 'foo' subdirectory
- downloader = self._makeDataConnection()
- d = self.client.queueStringCommand('LIST foo')
- wait(defer.gatherResults([d, downloader.d]))
+ # Download a listing of the 'foo' subdirectory. 'foo' has no files, so
+ # the file listing should be empty.
+ self._download('LIST foo', chainDeferred = d)
+ def checkDownload(download):
+ # 'foo' has no files, so the file listing should be empty
+ self.assertEqual('', download)
+ d.addCallback(checkDownload)
- # 'foo' has no files, so the file listing should be empty
- self.assertEqual('', downloader.buffer)
-
# Change the current working directory to 'foo'
- wait(self.client.queueStringCommand('CWD foo'))
+ def chdir(ignored):
+ return self.client.queueStringCommand('CWD foo')
+ d.addCallback(chdir)
# Download a listing from within 'foo', and again it should be empty
- downloader = self._makeDataConnection()
- d = self.client.queueStringCommand('LIST')
- wait(defer.gatherResults([d, downloader.d]))
- self.assertEqual('', downloader.buffer)
+ self._download('LIST', chainDeferred = d)
+ def checkDownload(download):
+ self.assertEqual('', download)
+ d.addCallback(checkDownload)
+ return d
+ def testManyLargeDownloads(self):
+ # Login
+ d = self._anonymousLogin()
+
+ # Download a range of different size files
+ for size in range(100000, 110000, 500):
+ self.rootfs.writefile_nocheck('/%d.txt' % (size,),
+ StringIO('x' * size))
+
+ self._download('RETR %d.txt' % (size,), chainDeferred = d)
+ def checkDownload(download, size = size):
+ self.assertEqual('x' * size, download)
+ d.addCallback(checkDownload)
+ return d
+
def testLIST_with_mtime(self):
- self._anonymousLogin()
+ d = self._anonymousLogin()
# Set up file with modification date set.
self.rootfs.writefile_nocheck('/foo', StringIO('x' * 20))
@@ -289,131 +296,133 @@
foo.modified = now
# Download a listing for foo.
- downloader = self._makeDataConnection()
- d = self.client.queueStringCommand('LIST /foo')
- wait(defer.gatherResults([d, downloader.d]))
+ self._download('LIST /foo', chainDeferred = d)
+ def checkDownload(download):
+ # check the data returned especially the date.
+ buf = download[:-2].split('\r\n')
+ self.assertEqual(len(buf), 1)
+ buf = buf[0]
+ buf = buf.split(None, 5)[5]
+ self.assertEqual(buf, '%s foo' % now.strftime('%b %d %H:%M'))
+ return d.addCallback(checkDownload)
- # check the data returned especially the date.
- buf = downloader.buffer[:-2].split('\r\n')
- self.assertEqual(len(buf), 1)
- buf = buf[0]
- buf = buf.split(None, 5)[5]
- self.assertEqual(buf, '%s foo' % now.strftime('%b %d %H:%M'))
-
def testLIST_nofile(self):
- self._anonymousLogin()
+ d = self._anonymousLogin()
- downloader = self._makeDataConnection()
- d = self.client.queueStringCommand('LIST /foo')
- responseLines = self._waitForCommandFailure(d)
+ def queueCommand(ignored):
+ d1 = self._makeDataConnection()
+ d2 = self.client.queueStringCommand('LIST /foo')
+ self.assertFailure(d2, ftp.CommandFailed)
+ def failed(exception):
+ self.assertEqual(['550 /foo: No such file or directory.'],
+ exception.args[0])
+ d2.addCallback(failed)
- self.assertEqual(['550 /foo: No such file or directory.'],
- responseLines)
+ return defer.gatherResults([d1, d2])
- d = downloader.transport.loseConnection()
+ d.addCallback(queueCommand)
return d
- def testManyLargeDownloads(self):
- # Login
- self._anonymousLogin()
- # Download a range of different size files
- for size in range(100000, 110000, 500):
- self.rootfs.writefile_nocheck('/%d.txt' % (size,),
- StringIO('x' * size))
-
- downloader = self._makeDataConnection()
- d = self.client.queueStringCommand('RETR %d.txt' % (size,))
- wait(defer.gatherResults([d, downloader.d]))
- self.assertEqual('x' * size, downloader.buffer)
-
-
class FTPServerPortDataConnectionTestCaes(FTPServerPasvDataConnectionTestCase,
test_ftp.FTPServerPortDataConnectionTestCase):
def setUp(self):
- FTPServerPasvDataConnectionTestCase.setUp(self)
self.dataPorts = []
+ return FTPServerPasvDataConnectionTestCase.setUp(self)
def tearDown(self):
l = [defer.maybeDeferred(port.stopListening) for port in self.dataPorts]
- wait(defer.DeferredList(l, fireOnOneErrback=True))
- return FTPServerPasvDataConnectionTestCase.tearDown(self)
+ d = defer.maybeDeferred(
+ FTPServerPasvDataConnectionTestCase.tearDown, self)
+ l.append(d)
+ return defer.DeferredList(l, fireOnOneErrback = True)
-from twisted.test.test_ftp import _BufferingProtocol
class ZopeFTPPermissionTestCases(FTPServerTestCase):
+
def setUp(self):
- FTPServerTestCase.setUp(self)
- self.filename = 'nopermissionfolder'
- self.rootfs.writefile('/%s' % self.filename, StringIO('x' * 100))
- file = self.rootfs.get(self.filename)
- file.grant('michael', 0)
- del file.access['anonymous']
+ def runZopePermSetup(ignored):
+ self.filename = 'nopermissionfolder'
+ self.rootfs.writefile('/%s' % self.filename, StringIO('x' * 100))
+ file = self.rootfs.get(self.filename)
+ file.grant('michael', 0)
+ del file.access['anonymous']
- def _makeDataConnection(self):
+ return FTPServerTestCase.setUp(self).addCallback(runZopePermSetup)
+
+ def _makeDataConnection(self, ignored = None):
# Establish a passive data connection (i.e. client connecting to
# server).
- responseLines = wait(self.client.queueStringCommand('PASV'))
- host, port = ftp.decodeHostPort(responseLines[-1][4:])
- downloader = wait(
- protocol.ClientCreator(reactor,
- _BufferingProtocol).connectTCP('127.0.0.1',
- port)
- )
- return downloader
+ d = self.client.queueStringCommand('PASV')
+ def gotPASV(responseLines):
+ host, port = ftp.decodeHostPort(responseLines[-1][4:])
+ cc = protocol.ClientCreator(reactor, test_ftp._BufferingProtocol)
+ return cc.connectTCP('127.0.0.1', port)
+ return d.addCallback(gotPASV)
+ def _download(self, command, chainDeferred=None):
+ if chainDeferred is None:
+ chainDeferred = defer.succeed(None)
+
+ chainDeferred.addCallback(self._makeDataConnection)
+ def queueCommand(downloader):
+ # wait for the command to return, and the download connection to be
+ # closed.
+ d1 = self.client.queueStringCommand(command)
+ d2 = downloader.d
+ return defer.gatherResults([d1, d2])
+ chainDeferred.addCallback(queueCommand)
+
+ def downloadDone((ignored, downloader)):
+ return downloader.buffer
+ return chainDeferred.addCallback(downloadDone)
+
def _michaelLogin(self):
- responseLines = wait(self.client.queueStringCommand('USER michael'))
- self.assertEquals(
- ['331 Password required for michael.'],
- responseLines
- )
-
- responseLines = wait(self.client.queueStringCommand(
- 'PASS michael')
- )
- self.assertEquals(
+ d = self.assertCommandResponse(
+ 'USER michael',
+ ['331 Password required for michael.'])
+ return self.assertCommandResponse(
+ 'PASS michael',
['230 User logged in, proceed'],
- responseLines
- )
+ chainDeferred = d)
def testNoSuchDirectory(self):
- self._michaelLogin()
- deferred = self.client.queueStringCommand('CWD /nosuchdir')
- failureResponseLines = self._waitForCommandFailure(deferred)
- self.failUnless(failureResponseLines[-1].startswith('550'),
- "Response didn't start with 550: %r" %
- failureResponseLines[-1])
+ d = self._michaelLogin()
+ return self.assertCommandFailed(
+ 'CWD /nosuchdir',
+ ['550 /nosuchdir: Permission denied.'],
+ chainDeferred = d)
def testListNonPermission(self):
- self._michaelLogin()
+ d = self._michaelLogin()
- # Download a listing
- downloader = self._makeDataConnection()
- d = self.client.queueStringCommand('NLST ')
- wait(defer.gatherResults([d, downloader.d]))
+ self._download('NLST ', chainDeferred = d)
+ def checkDownload(download):
+ # No files, so the file listing should be empty
+ filenames = download[:-2].split('\r\n')
+ filenames.sort()
+ self.assertEqual([self.filename], filenames)
+ return d.addCallback(checkDownload)
- # No files, so the file listing should be empty
- filenames = downloader.buffer[:-2].split('\r\n')
- filenames.sort()
- self.assertEqual([self.filename], filenames)
-
def testRETR_wo_Permission(self):
- self._michaelLogin()
+ d = self._michaelLogin()
- downloader = self._makeDataConnection()
- d = self.client.queueStringCommand('RETR %s' % self.filename)
- failureResponseLines = self._waitForCommandFailure(d)
- self.failUnless(failureResponseLines[-1].startswith('550'),
- "Response didn't start with 550: %r" %
- failureResponseLines[-1])
- if downloader.transport.connected:
- downloader.transport.loseConnection()
+ def queueCommand(ignored):
+ d1 = self._makeDataConnection()
+ d2 = self.client.queueStringCommand('RETR %s' % self.filename)
+ self.assertFailure(d2, ftp.CommandFailed)
+ def failed(exception):
+ self.assertEqual(
+ ['550 nopermissionfolder: No such file or directory.'],
+ exception.args[0])
+ d2.addCallback(failed)
+ return defer.gatherResults([d1, d2])
+ return d.addCallback(queueCommand)
+
+
def test_suite():
- test_zopetrial.patchtrial()
-
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(FTPServerTestCase))
@@ -424,5 +433,6 @@
return suite
+
if __name__ == '__main__':
test_suite()
Modified: Zope3/trunk/src/zope/app/twisted/ftp/tests/test_zopetrial.py
===================================================================
--- Zope3/trunk/src/zope/app/twisted/ftp/tests/test_zopetrial.py 2007-02-01 21:20:27 UTC (rev 72309)
+++ Zope3/trunk/src/zope/app/twisted/ftp/tests/test_zopetrial.py 2007-02-01 21:39:01 UTC (rev 72310)
@@ -11,7 +11,8 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""Contains helper functions and monkey patch to integrate twisted trial
+"""
+Contains helper functions and monkey patch to integrate twisted trial
tests with the Zope testrunner.
This code will be unneeded when Twisted 2.3 comes out has it contains
@@ -26,144 +27,13 @@
import unittest
from zope.testing import doctest
-import sets
-import time
import sys
-import os
+import os.path
import gc
import re
-import twisted.python.failure
-import twisted.trial.unittest
-import twisted.trial.reporter
-import twisted.trial.util
import zope.testing.testrunner
-class UnsupportedTrialFeature(Exception):
- """A feature of twisted.trial was used that pyunit cannot support."""
-
-
-class PyUnitResultAdapter(object):
- def __init__(self, original):
- self.original = original
-
- def _exc_info(self, err):
- from twisted.trial import reporter
- if isinstance(err, twisted.python.failure.Failure):
- # Unwrap the Failure into a exc_info tuple.
- # XXX: if err.tb is a real traceback and not stringified, we should
- # use that.
- err = (err.type, err.value, None)
- return err
-
- def startTest(self, method):
- self.original.startTest(method)
-
- def stopTest(self, method):
- self.original.stopTest(method)
-
- def addFailure(self, test, fail):
- if self.original.options.verbose > 2:
- print " (%.3f ms)" % (time.time() - self.original._start_time)
-
- self.original.failures.append((test, fail.getTraceback()))
- print
- print "Failure in test %s" % test
- print fail.getTraceback()
-
- if self.original.options.post_mortem:
- zope.testing.testrunner.post_mortem(exc_info)
-
- self.original.test_width = self.original.last_width = 0
-
- def addError(self, test, error):
- if self.original.options.verbose > 2:
- print " (%.3f ms)" % (time.time() - self.original._start_time)
-
- self.original.errors.append((test, error.getTraceback()))
- print
- print "Error in test %s" % test
- print error.getTraceback()
-
- if self.original.options.post_mortem:
- if self.original.options.resume_layer:
- print
- print '*'*70
- print ("Can't post-mortem debug when running a layer"
- " as a subprocess!")
- print '*'*70
- print
- else:
- zope.testing.testrunner.post_mortem(exc_info)
-
- self.original.test_width = self.original.last_width = 0
-
- def _unsupported(self, test, feature, info):
- self.original.addFailure(
- test,
- (UnsupportedTrialFeature,
- UnsupportedTrialFeature(feature, info),
- None))
-
- def addSkip(self, test, reason):
- self._unsupported(test, 'skip', reason)
-
- def addUnexpectedSuccess(self, test, todo):
- self._unsupported(test, 'unexpected success', todo)
-
- def addExpectedFailure(self, test, error):
- self._unsupported(test, 'expected failure', error)
-
- def addSuccess(self, test):
- self.original.addSuccess(test)
-
- def upDownError(self, method, warn = True, printStatus = True):
- pass
-
- def cleanupErrors(self, errs):
- pass
-
- def startSuite(self, name):
- pass
-
-
-orig_run = twisted.trial.unittest.TestCase.run
-
-def new_run(self, result):
- if not isinstance(result, twisted.trial.reporter.Reporter):
- result = PyUnitResultAdapter(result)
- orig_run(self, result)
- try:
- twisted.trial.util._Janitor().postCaseCleanup()
- except:
- result.cleanupErrors(twisted.python.failure.Failure(sys.exc_info()))
-
-def patchtrial():
- #
- # Patch the twisted.trial.unittest.TestCase class inorder for it to run
- # within the Zope testrunner. Only patch this class if we need to. Newer
- # versions of Twisted don't need to be patched.
- #
- try:
- twisted.trial.unittest.PyUnitResultAdapter
- except AttributeError:
- ## old version of twisted we need to patch twisted.
- twisted.trial.unittest.TestCase.run = new_run
-
-def killthreads():
- """A lot of tests will start threads which the Zope testrunner complains
- about. You can use this method to kill off these threads.
- """
- from twisted.internet import reactor, interfaces
- from twisted.python import threadpool
- if interfaces.IReactorThreads.providedBy(reactor):
- reactor.suggestThreadPoolSize(0)
- if reactor.threadpool:
- reactor.threadpool.stop()
- reactor.threadpool = None
- reactor.threadpool = threadpool.ThreadPool(0, 10)
- reactor.threadpool.start()
-
orig_configure_logging = zope.testing.testrunner.configure_logging
def setUp(test):
@@ -195,9 +65,6 @@
sys.modules.update(test.globs['saved-sys-info'][2])
def test_suite():
- # patch trial before starting so that our test fail when they should.
- patchtrial()
-
# copied from zope.testing.testrunner
import zope.testing.renormalizing
checker = zope.testing.renormalizing.RENormalizing([
Modified: Zope3/trunk/src/zope/app/twisted/ftp/tests/trial.txt
===================================================================
--- Zope3/trunk/src/zope/app/twisted/ftp/tests/trial.txt 2007-02-01 21:20:27 UTC (rev 72309)
+++ Zope3/trunk/src/zope/app/twisted/ftp/tests/trial.txt 2007-02-01 21:39:01 UTC (rev 72310)
@@ -27,25 +27,12 @@
Running unit tests:
<BLANKLINE>
Error in test test_error (trialtest.TestTrialTests)
- Traceback (most recent call last):
- ...
- --- <exception caught here> ---
- File "...twisted/internet/defer.py", Line NNN, in maybeDeferred
- result = f(*args, **kw)
- File "...app/twisted/ftp/tests/trialtest.py", Line NNN, in test_error
- raise Exception, "this test is a broken trial test :-)"
- exceptions.Exception: this test is a broken trial test :-)
+ Exception: this test is a broken trial test :-)
<BLANKLINE>
<BLANKLINE>
+ <BLANKLINE>
Failure in test test_failure (trialtest.TestTrialTests)
- Traceback (most recent call last):
- ...
- --- <exception caught here> ---
- File "...twisted/internet/defer.py", Line NNN, in maybeDeferred
- result = f(*args, **kw)
- File "...app/twisted/ftp/tests/trialtest.py", Line NNN, in test_failure
- self.assert_(False, "I am a failed trial test")
- twisted.trial.unittest.FailTest: I am a failed trial test
+ FailTest: I am a failed trial test
<BLANKLINE>
Ran 3 tests with 1 failures and 1 errors in N.NNN seconds.
True
@@ -59,36 +46,15 @@
Running unit tests:
<BLANKLINE>
Error in test test_assert_ok (trialtestfs.TestTrialBrokenSetup)
- Traceback (most recent call last):
- ...
- --- <exception caught here> ---
- File "...twisted/internet/defer.py", line 107, in maybeDeferred
- result = f(*args, **kw)
- File "...app/twisted/ftp/tests/trialtestfs.py", line 28, in setUp
- raise Exception, 'broken setup'
- exceptions.Exception: broken setup
+ Exception: broken setup
<BLANKLINE>
<BLANKLINE>
Error in test test_error (trialtestfs.TestTrialBrokenSetup)
- Traceback (most recent call last):
- ...
- --- <exception caught here> ---
- File "...twisted/internet/defer.py", line 107, in maybeDeferred
- result = f(*args, **kw)
- File "...app/twisted/ftp/tests/trialtestfs.py", line 28, in setUp
- raise Exception, 'broken setup'
- exceptions.Exception: broken setup
+ Exception: broken setup
<BLANKLINE>
<BLANKLINE>
Error in test test_failure (trialtestfs.TestTrialBrokenSetup)
- Traceback (most recent call last):
- ...
- --- <exception caught here> ---
- File "...twisted/internet/defer.py", line 107, in maybeDeferred
- result = f(*args, **kw)
- File "...app/twisted/ftp/tests/trialtestfs.py", line 28, in setUp
- raise Exception, 'broken setup'
- exceptions.Exception: broken setup
+ Exception: broken setup
<BLANKLINE>
Ran 3 tests with 0 failures and 3 errors in N.NNN seconds.
True
@@ -102,60 +68,23 @@
Running unit tests:
<BLANKLINE>
Error in test test_assert_ok (trialtestft.TestTrialBrokenTeardown)
- Traceback (most recent call last):
- ...
- --- <exception caught here> ---
- File "...twisted/internet/defer.py", line 107, in maybeDeferred
- result = f(*args, **kw)
- File "...app/twisted/ftp/tests/trialtestft.py", line 30, in tearDown
- raise Exception, 'broken tearDown'
- exceptions.Exception: broken tearDown
+ Exception: broken tearDown
<BLANKLINE>
<BLANKLINE>
Error in test test_error (trialtestft.TestTrialBrokenTeardown)
- Traceback (most recent call last):
- ...
- --- <exception caught here> ---
- File "...twisted/internet/defer.py", line 107, in maybeDeferred
- result = f(*args, **kw)
- File "...app/twisted/ftp/tests/trialtestft.py", line 33, in test_error
- raise Exception, "this test is a broken trial test :-)"
- exceptions.Exception: this test is a broken trial test :-)
+ Exception: this test is a broken trial test :-)
<BLANKLINE>
<BLANKLINE>
Error in test test_error (trialtestft.TestTrialBrokenTeardown)
- Traceback (most recent call last):
- ...
- --- <exception caught here> ---
- File "...twisted/internet/defer.py", line 107, in maybeDeferred
- result = f(*args, **kw)
- File "...app/twisted/ftp/tests/trialtestft.py", line 30, in tearDown
- raise Exception, 'broken tearDown'
- exceptions.Exception: broken tearDown
+ Exception: broken tearDown
<BLANKLINE>
<BLANKLINE>
Failure in test test_failure (trialtestft.TestTrialBrokenTeardown)
- Traceback (most recent call last):
- ...
- --- <exception caught here> ---
- File "...twisted/internet/defer.py", line 107, in maybeDeferred
- result = f(*args, **kw)
- File "...app/twisted/ftp/tests/trialtestft.py", line 36, in test_failure
- self.assert_(False, "I am a failed trial test")
- File "...twisted/trial/unittest.py", line 223, in failUnless
- raise self.failureException(msg)
- twisted.trial.unittest.FailTest: I am a failed trial test
+ FailTest: I am a failed trial test
<BLANKLINE>
<BLANKLINE>
Error in test test_failure (trialtestft.TestTrialBrokenTeardown)
- Traceback (most recent call last):
- ...
- --- <exception caught here> ---
- File "...twisted/internet/defer.py", line 107, in maybeDeferred
- result = f(*args, **kw)
- File "...app/twisted/ftp/tests/trialtestft.py", line 30, in tearDown
- raise Exception, 'broken tearDown'
- exceptions.Exception: broken tearDown
+ Exception: broken tearDown
<BLANKLINE>
Ran 3 tests with 1 failures and 4 errors in 0.118 seconds.
True
@@ -166,7 +95,7 @@
>>> import twisted.trial.util
>>> old_doCleanReactor = twisted.trial.util._Janitor.do_cleanReactor
>>> def new_doCleanReactor(cls):
- ... raise Exception, "Can't clean the reactor"
+ ... raise Exception("Can't clean the reactor")
...
>>> twisted.trial.util._Janitor.do_cleanReactor = new_doCleanReactor
@@ -176,25 +105,11 @@
Running unit tests:
<BLANKLINE>
Error in test test_error (trialtest.TestTrialTests)
- Traceback (most recent call last):
- ...
- --- <exception caught here> ---
- File "...twisted/internet/defer.py", Line NNN, in maybeDeferred
- result = f(*args, **kw)
- File "...app/twisted/ftp/tests/trialtest.py", Line NNN, in test_error
- raise Exception, "this test is a broken trial test :-)"
- exceptions.Exception: this test is a broken trial test :-)
+ Exception: this test is a broken trial test :-)
<BLANKLINE>
<BLANKLINE>
Failure in test test_failure (trialtest.TestTrialTests)
- Traceback (most recent call last):
- ...
- --- <exception caught here> ---
- File "...twisted/internet/defer.py", Line NNN, in maybeDeferred
- result = f(*args, **kw)
- File "...app/twisted/ftp/tests/trialtest.py", Line NNN, in test_failure
- self.assert_(False, "I am a failed trial test")
- twisted.trial.unittest.FailTest: I am a failed trial test
+ FailTest: I am a failed trial test
<BLANKLINE>
Ran 3 tests with 1 failures and 1 errors in N.NNN seconds.
True
Modified: Zope3/trunk/src/zope/app/twisted/ftp/tests/trialtest.py
===================================================================
--- Zope3/trunk/src/zope/app/twisted/ftp/tests/trialtest.py 2007-02-01 21:20:27 UTC (rev 72309)
+++ Zope3/trunk/src/zope/app/twisted/ftp/tests/trialtest.py 2007-02-01 21:39:01 UTC (rev 72310)
@@ -33,7 +33,7 @@
pass
def test_error(self):
- raise Exception, "this test is a broken trial test :-)"
+ raise Exception("this test is a broken trial test :-)")
def test_failure(self):
self.assert_(False, "I am a failed trial test")
Modified: Zope3/trunk/src/zope/app/twisted/ftp/tests/trialtestfs.py
===================================================================
--- Zope3/trunk/src/zope/app/twisted/ftp/tests/trialtestfs.py 2007-02-01 21:20:27 UTC (rev 72309)
+++ Zope3/trunk/src/zope/app/twisted/ftp/tests/trialtestfs.py 2007-02-01 21:39:01 UTC (rev 72310)
@@ -23,13 +23,13 @@
class TestTrialBrokenSetup(twisted.trial.unittest.TestCase):
def setUp(self):
- raise Exception, 'broken setup'
+ raise Exception("broken setup")
def tearDown(self):
pass
def test_error(self):
- raise Exception, "this test is a broken trial test :-)"
+ raise Exception("this test is a broken trial test :-)")
def test_failure(self):
self.assert_(False, "I am a failed trial test")
Modified: Zope3/trunk/src/zope/app/twisted/ftp/tests/trialtestft.py
===================================================================
--- Zope3/trunk/src/zope/app/twisted/ftp/tests/trialtestft.py 2007-02-01 21:20:27 UTC (rev 72309)
+++ Zope3/trunk/src/zope/app/twisted/ftp/tests/trialtestft.py 2007-02-01 21:39:01 UTC (rev 72310)
@@ -26,10 +26,10 @@
pass
def tearDown(self):
- raise Exception, 'broken tearDown'
+ raise Exception("broken tearDown")
def test_error(self):
- raise Exception, "this test is a broken trial test :-)"
+ raise Exception("this test is a broken trial test :-)")
def test_failure(self):
self.assert_(False, "I am a failed trial test")
Modified: Zope3/trunk/src/zope/app/twisted/http.py
===================================================================
--- Zope3/trunk/src/zope/app/twisted/http.py 2007-02-01 21:20:27 UTC (rev 72309)
+++ Zope3/trunk/src/zope/app/twisted/http.py 2007-02-01 21:39:01 UTC (rev 72310)
@@ -29,11 +29,11 @@
max_stringio = 100*1000 # Should this be configurable?
class Prebuffer(resource.WrapperResource):
- def hook(self, ctx):
- req = iweb.IRequest(ctx)
- content_length = req.headers.getHeader('content-length')
- if content_length is not None and int(content_length) > max_stringio:
+ def hook(self, req):
+ content_length = req.stream.length
+
+ if content_length > max_stringio:
temp = tempfile.TemporaryFile()
def done(_):
temp.seek(0)
@@ -41,7 +41,6 @@
req.stream = stream.FileStream(temp, useMMap=False)
# Hm, this shouldn't be required:
req.stream.doStartReading = None
-
else:
temp = StringIO()
def done(_):
@@ -49,15 +48,9 @@
req.stream = stream.MemoryStream(temp.getvalue())
# Hm, this shouldn't be required:
req.stream.doStartReading = None
-
+
return stream.readStream(req.stream, temp.write).addCallback(done)
- # Oops, fix missing () in lambda in WrapperResource
- def locateChild(self, ctx, segments):
- x = self.hook(ctx)
- if x is not None:
- return x.addCallback(lambda data: (self.res, segments))
- return self.res, segments
def createHTTPFactory(db):
resource = wsgi.WSGIResource(WSGIPublisherApplication(db))
@@ -69,6 +62,7 @@
http = ServerType(createHTTPFactory, 8080)
https = SSLServerType(createHTTPFactory, 8443)
+
def createPMHTTPFactory(db):
resource = wsgi.WSGIResource(PMDBWSGIPublisherApplication(db))
resource = log.LogWrapperResource(resource)
Modified: Zope3/trunk/src/zope/app/twisted/log.txt
===================================================================
--- Zope3/trunk/src/zope/app/twisted/log.txt 2007-02-01 21:20:27 UTC (rev 72309)
+++ Zope3/trunk/src/zope/app/twisted/log.txt 2007-02-01 21:39:01 UTC (rev 72310)
@@ -51,9 +51,10 @@
... def getRemoteHost(self):
... return type('TestRemoteHost', (), {'host': '127.0.0.1'})
- >>> chanRequest = TestHTTPChannel(None, 'GET /index.html HTTP/1.1', 1)
+ >>> chanRequest = TestHTTPChannel(None, 1)
>>> request = http.Request(chanRequest, 'GET', '/index.html', (1, 1),
- ... http_headers.Headers())
+ ... 0, http_headers.Headers())
+ >>> request.remoteAddr = chanRequest.getRemoteHost()
>>> response = http.Response()
>>> response.headers.setHeader('date', 1120000000)
@@ -69,7 +70,7 @@
>>> eventDict = {'interface': iweb.IRequest,
... 'request': request, 'response': response,
- ... 'context': FauxContext()}
+ ... 'loginfo': FauxContext()}
If we now emit a log event, we should receive an entry:
Modified: Zope3/trunk/src/zope/app/twisted/tests/test_inputbuffering.py
===================================================================
--- Zope3/trunk/src/zope/app/twisted/tests/test_inputbuffering.py 2007-02-01 21:20:27 UTC (rev 72309)
+++ Zope3/trunk/src/zope/app/twisted/tests/test_inputbuffering.py 2007-02-01 21:39:01 UTC (rev 72310)
@@ -17,6 +17,9 @@
an application thread.
Also, test that both small and (somewhat) large inputs are handled correctly.
+We do this by marking the requests are processed in the correct order. Namely that
+the 'good' request is processed before the 'bad' request. This is done by marking
+the requests with the HTTP header 'X-Thread-Identify'.
>>> instance = Instance()
>>> instance.start()
@@ -28,6 +31,7 @@
>>> bad.connect(('localhost', instance.port))
>>> bad.sendall('GET http://localhost:%s/echo HTTP/1.1\r\n'
... % instance.port)
+ >>> bad.sendall('X-Thread-Identify: bad\r\n')
>>> bad.sendall('Content-Length: 10\r\n')
>>> bad.sendall('Content-Type: text/plain\r\n')
>>> bad.sendall('\r\n')
@@ -41,6 +45,7 @@
>>> s.connect(('localhost', instance.port))
>>> s.sendall('GET http://localhost:%s/echo HTTP/1.1\r\n'
... % instance.port)
+ >>> s.sendall('X-Thread-Identify: good\r\n')
>>> s.sendall('Content-Length: 120005\r\n')
>>> s.sendall('Content-Type: text/plain\r\n')
>>> s.sendall('\r\n')
@@ -55,9 +60,18 @@
>>> s.close()
+ >>> bad.sendall('end\r\n' + 'xxxxxxxxxx\r\n')
+ >>> f = bad.makefile()
- >>> bad.sendall('end\r\n' + 'xxxxxxxxxx\n')
+If the requests were processed in the wrong order then the first line of the
+'bad' request will be 'HTTP/1.1 500 Internal Server Error\r\n'
+
+ >>> f.readline()
+ 'HTTP/1.1 200 OK\r\n'
+
+ >>> f.close()
>>> bad.close()
+
>>> instance.stop()
>>> shutil.rmtree(instance.dir)
@@ -78,6 +92,8 @@
import ZEO.tests.testZEO # we really need another library
import ZEO.tests.forker
+# This is a list of the ordering we expect to receive the requests in.
+received = ['good', 'bad']
class Echo:
@@ -87,6 +103,16 @@
def echo(self):
s = 0
result = []
+
+ rid = self.request.getHeader('X-Thread-Identify', None)
+ if rid is None:
+ raise ValueError("""All requests should be marked with
+ the 'X-Thread-Identify' header""")
+
+ expectedrid = received.pop(0)
+ if expectedrid != rid:
+ raise ValueError("Requests received in the wrong order.")
+
while 1:
l = self.request.bodyStream.readline()
s += len(l)
@@ -96,6 +122,7 @@
break
return ''.join(result)
+
class Instance:
def __init__(self, dir=None, name=None, zeo_port=1):
Copied: Zope3/trunk/src/zope/app/twisted/tests/test_largeinput.py (from rev 72305, Zope3/branches/mkerrin-twisted-upgrade/src/zope/app/twisted/tests/test_largeinput.py)
More information about the Zope3-Checkins
mailing list