1
##############################################################################
3
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
6
# This software is subject to the provisions of the Zope Public License,
7
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
# FOR A PARTICULAR PURPOSE.
13
##############################################################################
14
"""Provide a standard cleanup registry
16
Unit tests that change global data should include the CleanUp base
17
class, which provides simpler setUp and tearDown methods that call
18
global-data cleanup routines::
20
class Test(CleanUp, unittest.TestCase):
24
If custom setUp or tearDown are needed, then the base routines should
28
super(Test, self).tearDown()
31
Cleanup routines for global data should be registered by passing them to
35
addCleanUp(pigRegistry._clear)
38
$Id: cleanup.py 110538 2010-04-06 03:02:54Z tseaver $
42
def addCleanUp(func, args=(), kw={}):
43
"""Register a cleanup routines
45
Pass a function to be called to cleanup global data.
46
Optional argument tuple and keyword arguments may be passed.
48
_cleanups.append((func, args, kw))
50
class CleanUp(object):
51
"""Mix-in class providing clean-up setUp and tearDown routines."""
54
"""Clean up global data."""
57
setUp = tearDown = cleanUp
61
"""Clean up global data."""
62
for func, args, kw in _cleanups:
65
setUp = tearDown = cleanUp