[Zope-Checkins] CVS: Zope3/lib/python/Zope/Testing - CleanUp.py:1.1.2.1 __init__.py:1.3.38.3

Jim Fulton jim@cvs.zope.org
Tue, 19 Feb 2002 11:05:12 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/Testing
In directory cvs.zope.org:/tmp/cvs-serv7148/lib/python/Zope/Testing

Modified Files:
      Tag: Zope-3x-branch
	__init__.py 
Added Files:
      Tag: Zope-3x-branch
	CleanUp.py 
Log Message:
Refactored tests to use a global-data cleanup framework.
This avoids a lot of messy clean-up code needed for tests that
use global registries, such as component services.

It is really important to make sure global registries get registered
with this framework.

See the doc strings in Zope.Testing.CleannUp.


=== Added File Zope3/lib/python/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::

  from Zope.Testing.CleanUp import addCleanUp
  addCleanUp(roleRegistry._clear)


Revision information:
$Id: CleanUp.py,v 1.1.2.1 2002/02/19 16:05:11 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))

def cleanUp(ignored=None):
    """Clean up global data
    """
    for func, args, kw in _cleanups:
        func(*args, **kw)

class CleanUp:
    """Mix-in class providing clean-up setUp and tearDown routines
    """
    tearDown = setUp = cleanUp


=== Zope3/lib/python/Zope/Testing/__init__.py 1.3.38.2 => 1.3.38.3 ===
 $Id$
 """
-import os
 
-def pdir(path):
-    return os.path.split(path)[0]
+#XXX we don't seem to need this. We should ax this soon. :)
+def setUpEnv():
 
-# Set the INSTANCE_HOME to the Testing package directory
-os.environ['INSTANCE_HOME'] = INSTANCE_HOME = pdir(__file__)
+    import os
 
-# Set the SOFTWARE_HOME to the directory containing the Testing package
-os.environ['SOFTWARE_HOME'] = SOFTWARE_HOME = pdir(INSTANCE_HOME)
+    def pdir(path):
+        return os.path.split(path)[0]
 
-# Prevent useless initialization by pretending to be a ZEO client
-os.environ['ZEO_CLIENT'] = '1'
+    # Set the INSTANCE_HOME to the Testing package directory
+    os.environ['INSTANCE_HOME'] = INSTANCE_HOME = pdir(__file__)
 
-from Builder import allZopeTests
+    # Set the SOFTWARE_HOME to the directory containing the Testing package
+    os.environ['SOFTWARE_HOME'] = SOFTWARE_HOME = pdir(INSTANCE_HOME)
 
+    # Prevent useless initialization by pretending to be a ZEO client
+    os.environ['ZEO_CLIENT'] = '1'
+
+def allZopeTests():
+    #setUpEnv()
+    from Builder import allZopeTests
+    return allZopeTests()