[Zope3-checkins] CVS: Zope3/src/zope/testing - __init__.py:1.2 cleanup.py:1.2
Jim Fulton
jim@zope.com
Wed, 25 Dec 2002 09:16:05 -0500
Update of /cvs-repository/Zope3/src/zope/testing
In directory cvs.zope.org:/tmp/cvs-serv20790/src/zope/testing
Added Files:
__init__.py cleanup.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/testing/__init__.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:16:04 2002
+++ Zope3/src/zope/testing/__init__.py Wed Dec 25 09:15:34 2002
@@ -0,0 +1,31 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""
+Set up testing environment
+
+$Id$
+"""
+import os
+
+def patchTracebackModule():
+ """Use the ExceptionFormatter to show more info in tracebacks.
+ """
+ from zope.exceptions.exceptionformatter import format_exception
+ import traceback
+ traceback.format_exception = format_exception
+
+# Don't use the new exception formatter by default, since it
+# doesn't show filenames.
+if os.environ.get('NEW_ZOPE_EXCEPTION_FORMATTER', 0):
+ patchTracebackModule()
=== Zope3/src/zope/testing/cleanup.py 1.1 => 1.2 ===
--- /dev/null Wed Dec 25 09:16:04 2002
+++ Zope3/src/zope/testing/cleanup.py Wed Dec 25 09:15:34 2002
@@ -0,0 +1,60 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Provide a standard cleanup registry
+
+Unit tests that change global data should include the CleanUp base
+class, which provides simpler setUp and tearDown methods that call
+global-data cleanup routines::
+
+ class Test(CleanUp, unittest.TestCase):
+
+ ....
+
+If custom setUp or tearDown are needed, then the base reoutines should
+be called, as in::
+
+ def tearDown(self):
+ CleanUp.tearDown(self)
+ ....
+
+Cleanup routines for global data should be registered by passing them to
+addCleanup::
+
+
+ addCleanUp(roleRegistry._clear)
+
+
+Revision information:
+$Id$
+"""
+
+_cleanups = []
+
+def addCleanUp(func, args=(), kw={}):
+ """Register a cleanup routines
+
+ Pass a function to be called to cleanup global data.
+ Optional argument tuple and keyword arguments may be passed.
+ """
+ _cleanups.append((func, args, kw))
+
+class CleanUp:
+ """Mix-in class providing clean-up setUp and tearDown routines."""
+
+ def cleanUp(self):
+ """Clean up global data."""
+ for func, args, kw in _cleanups:
+ func(*args, **kw)
+
+ setUp = tearDown = cleanUp