[Zope3-checkins] CVS: Zope3/src/zope/testing - __init__.py:1.1.2.1 cleanup.py:1.1.2.1

Jim Fulton jim@zope.com
Mon, 23 Dec 2002 14:33:34 -0500


Update of /cvs-repository/Zope3/src/zope/testing
In directory cvs.zope.org:/tmp/cvs-serv19908/zope/testing

Added Files:
      Tag: NameGeddon-branch
	__init__.py cleanup.py 
Log Message:
Initial renaming before debugging

=== Added File Zope3/src/zope/testing/__init__.py ===
##############################################################################
#
# 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: __init__.py,v 1.1.2.1 2002/12/23 19:33:33 jim Exp $
"""
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()



=== Added File Zope3/src/zope/testing/cleanup.py ===
##############################################################################
#
# 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: cleanup.py,v 1.1.2.1 2002/12/23 19:33:33 jim Exp $
"""

_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