[Zope3-checkins] CVS: Zope3/src/zope/server/tests - __init__.py:1.2 asyncerror.py:1.2

Jim Fulton jim@zope.com
Wed, 25 Dec 2002 09:15:58 -0500


Update of /cvs-repository/Zope3/src/zope/server/tests
In directory cvs.zope.org:/tmp/cvs-serv20790/src/zope/server/tests

Added Files:
	__init__.py asyncerror.py 
Log Message:
Grand renaming:

- Renamed most files (especially python modules) to lower case.

- Moved views and interfaces into separate hierarchies within each
  project, where each top-level directory under the zope package
  is a separate project.

- Moved everything to src from lib/python.

  lib/python will eventually go away. I need access to the cvs
  repository to make this happen, however.

There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.



=== Zope3/src/zope/server/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:58 2002
+++ Zope3/src/zope/server/tests/__init__.py	Wed Dec 25 09:15:27 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.


=== Zope3/src/zope/server/tests/asyncerror.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:58 2002
+++ Zope3/src/zope/server/tests/asyncerror.py	Wed Dec 25 09:15:27 2002
@@ -0,0 +1,54 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Mixin class to turn uncaught asyncore errors into test failues.
+
+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.
+
+$Id$
+"""
+
+__metaclass__ = type
+
+import asyncore
+import sys
+import traceback
+
+class AsyncoreErrorHook:
+    """Convert asyncore errors into unittest failures.
+
+    Call hook_asyncore_error in setUp() and unhook_asyncore_error() in
+    tearDown(), or use super() to call setUp() and tearDown() here.
+    """
+
+    def setUp(self):
+        self.hook_asyncore_error()
+
+    def tearDown(self):
+        self.unhook_asycnore_error()
+
+    def hook_asyncore_error(self):
+        self._asyncore_traceback = asyncore.compact_traceback
+        asyncore.compact_traceback = self.handle_asyncore_error
+
+    def unhook_asyncore_error(self):
+        asyncore.compact_traceback = self._asyncore_traceback
+
+    def handle_asyncore_error(self):
+        L = traceback.format_exception(*sys.exc_info())
+        self.fail("".join(L))