vendor/Five/1.2b-r20590

view testing/cleanup.py @ 0:3673ed425f80

Vendor import of Five 1.2b+ (r20590)
author fguillaume
date Fri, 02 Dec 2005 20:25:42 +0000
parents
children
line source
1 ##############################################################################
2 #
3 # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
4 # All Rights Reserved.
5 #
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.
12 #
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):
22 ....
24 If custom setUp or tearDown are needed, then the base routines should
25 be called, as in::
27 def tearDown(self):
28 super(Test, self).tearDown()
29 ....
31 Cleanup routines for global data should be registered by passing them to
32 addCleanup::
35 addCleanUp(pigRegistry._clear)
38 $Id: cleanup.py 18831 2005-10-21 18:07:37Z yuppie $
39 """
40 _cleanups = []
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.
47 """
48 _cleanups.append((func, args, kw))
50 class CleanUp(object):
51 """Mix-in class providing clean-up setUp and tearDown routines."""
53 def cleanUp(self):
54 """Clean up global data."""
55 cleanUp()
57 setUp = tearDown = cleanUp
60 def cleanUp():
61 """Clean up global data."""
62 for func, args, kw in _cleanups:
63 func(*args, **kw)
65 setUp = tearDown = cleanUp