[Zope3-checkins] CVS: Zope3/lib/python/Zope/Server/HTTP/tests - testHTTPServer.py:1.3

Jeremy Hylton jeremy@zope.com
Fri, 20 Dec 2002 18:50:38 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/Server/HTTP/tests
In directory cvs.zope.org:/tmp/cvs-serv13078/HTTP/tests

Modified Files:
	testHTTPServer.py 
Log Message:
Add a framework for converting asyncore errors to unittest errors.

By default, asyncore handles uncaught exceptions in dispatchers by
printing a message to the console.  If a test causes such uncaught
exceptions, the test is marked as a failure, because asyncore handles
the exception.  This framework causes the unit test to fail.  If code
being tested expects the errors to occur, it can add code to prevent
the error from propagating all the way back to asyncore.


=== Zope3/lib/python/Zope/Server/HTTP/tests/testHTTPServer.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/Server/HTTP/tests/testHTTPServer.py:1.2	Mon Jun 10 19:29:36 2002
+++ Zope3/lib/python/Zope/Server/HTTP/tests/testHTTPServer.py	Fri Dec 20 18:50:08 2002
@@ -25,6 +25,7 @@
 from Zope.Server.HTTP.HTTPServer import HTTPServer
 from Zope.Server.Adjustments import Adjustments
 from Zope.Server.ITask import ITask
+from Zope.Server.tests.asyncerror import AsyncoreErrorHook
 
 from httplib import HTTPConnection
 from httplib import HTTPResponse as ClientHTTPResponse
@@ -73,11 +74,12 @@
         pass
 
 
-class Tests(unittest.TestCase):
+class Tests(unittest.TestCase, AsyncoreErrorHook):
 
     def setUp(self):
         td.setThreadCount(4)
         self.orig_map_size = len(socket_map)
+        self.hook_asyncore_error()
         self.server = EchoHTTPServer(LOCALHOST, SERVER_PORT,
                                      task_dispatcher=td, adj=my_adj)
         if CONNECT_TO_PORT == 0:
@@ -103,13 +105,14 @@
                 break
             if time() >= timeout:
                 self.fail('Leaked a socket: %s' % `socket_map`)
-            poll(0.1, socket_map)
+            poll(0.1)
+        self.unhook_asyncore_error()
 
     def loop(self):
         while self.run_loop:
             self.counter = self.counter + 1
             #print 'loop', self.counter
-            poll(0.1, socket_map)
+            poll(0.1)
 
     def testEchoResponse(self, h=None, add_headers=None, body=''):
         if h is None: