[Checkins] SVN: Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/ - Made base.TestCase a new-style class.

Stefan H. Holek stefan at epy.co.at
Sun Mar 26 20:24:50 EST 2006


Log message for revision 66216:
  - Made base.TestCase a new-style class.
  - Added placeless.py for Z3-style setup. Thanks to Whit Morriss.
  

Changed:
  U   Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/__init__.py
  U   Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/base.py
  U   Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt
  A   Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/placeless.py
  A   Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/testPlaceless.py
  U   Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/zopedoctest/__init__.py

-=-
Modified: Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/__init__.py
===================================================================
--- Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/__init__.py	2006-03-26 23:15:02 UTC (rev 66215)
+++ Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/__init__.py	2006-03-27 01:24:46 UTC (rev 66216)
@@ -51,6 +51,7 @@
 
 import zopedoctest as doctest
 import transaction
+import placeless
 
 Zope = Zope2
 

Modified: Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/base.py
===================================================================
--- Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/base.py	2006-03-26 23:15:02 UTC (rev 66215)
+++ Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/base.py	2006-03-27 01:24:46 UTC (rev 66216)
@@ -40,7 +40,7 @@
 
 
 
-class TestCase(profiler.Profiled, unittest.TestCase):
+class TestCase(profiler.Profiled, unittest.TestCase, object):
     '''Base test case for Zope testing
     '''
 

Modified: Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt
===================================================================
--- Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt	2006-03-26 23:15:02 UTC (rev 66215)
+++ Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt	2006-03-27 01:24:46 UTC (rev 66216)
@@ -1,4 +1,4 @@
-Unreleased
+Zope 2.8 edition
 - Don't break if Python distros ship without profile support (Debian, Ubuntu).
 - Functional.publish() would hang if it got a request_method argument other
   than GET or HEAD while omitting the stdin argument.
@@ -7,6 +7,8 @@
 - Made functional doctests set cookie related headers.
 - Made functional doctests set the Www-Authenticate header.
 - Made sure logging is configured. Read $INSTANCE_HOME/log.ini if it exists.
+- Made base.TestCase a new-style class.
+- Added placeless.py for Z3-style setup. Thanks to Whit Morriss.
 
 0.9.8 (Zope 2.8 edition)
 - Renamed 'doctest' package to 'zopedoctest' because of name-shadowing

Added: Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/placeless.py
===================================================================
--- Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/placeless.py	2006-03-26 23:15:02 UTC (rev 66215)
+++ Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/placeless.py	2006-03-27 01:24:46 UTC (rev 66216)
@@ -0,0 +1,63 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""Placeless setup
+
+$Id: __init__.py 30566 2005-05-30 22:37:34Z shh $
+"""
+
+from zope.app.tests.placelesssetup import setUp, tearDown
+
+# For convenience
+from Products.Five import zcml
+
+
+def callZCML(zcml_callback):
+    if callable(zcml_callback):
+        zcml_callback()
+    else:
+        for func in zcml_callback:
+            func()
+
+
+def temporaryPlacelessSetUp(orig_func, placeless_available=True, required_zcml=[]):
+    '''A wrapper for test functions that require CA to be available and/or
+       some ZCML to be run during test fixture creation.
+    '''
+    if not placeless_available:
+        return orig_func
+
+    def wrapper(*args, **kw):
+        __doc__ = '''%s ::
+
+        @param required_zcml callback or iterable of callbacks
+        required for setup of configuration needed by fixture
+        creation.
+        ''' % orig_func.__doc__
+
+        # Setup the placeless stuff that's needed to create a fixture
+        setUp()
+
+        # Call any necessary callbacks for setting up ZCML
+        callZCML(required_zcml)
+        if kw.has_key('required_zcml'):
+            zcml = kw.pop('required_zcml')
+            callZCML(zcml)
+
+        value = orig_func(*args, **kw)
+
+        # And tear it down
+        tearDown()
+        return value
+
+    return wrapper
+


Property changes on: Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/placeless.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/testPlaceless.py
===================================================================
--- Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/testPlaceless.py	2006-03-26 23:15:02 UTC (rev 66215)
+++ Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/testPlaceless.py	2006-03-27 01:24:46 UTC (rev 66216)
@@ -0,0 +1,101 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""Placeless setup tests
+
+$Id:$
+"""
+
+import os, sys
+if __name__ == '__main__':
+    execfile(os.path.join(sys.path[0], 'framework.py'))
+
+from Testing import ZopeTestCase
+
+from Testing.ZopeTestCase.placeless import setUp, tearDown
+from Testing.ZopeTestCase.placeless import zcml
+from Testing.ZopeTestCase.placeless import temporaryPlacelessSetUp
+
+import Products.Five.tests
+try:
+    from Products.Five.tests.adapters import IAdapted
+    from Products.Five.tests.adapters import Adaptable
+except ImportError:
+    pass # Five 1.0
+
+
+def setupZCML():
+    zcml.load_config('meta.zcml', Products.Five)
+    zcml.load_config('permissions.zcml', Products.Five)
+    zcml.load_config('directives.zcml', Products.Five.tests)
+
+
+class TestPlacelessSetUp(ZopeTestCase.ZopeTestCase):
+    '''Tests ZopeTestCase with placeless setup'''
+
+    def afterSetUp(self):
+        tearDown()
+
+    def beforeTearDown(self):
+        tearDown()
+
+    def testSimple(self):
+        # SetUp according to Five's adapter test
+        setUp()
+        setupZCML()
+        # Now we have a fixture that should work for adaptation
+        adapted = IAdapted(Adaptable())
+        self.assertEqual(adapted.adaptedMethod(), 'Adapted: The method')
+
+    def func(self, *args):
+        adapted = IAdapted(Adaptable())
+        return True
+
+    def testNoCA(self):
+        self.assertRaises(TypeError, self.func)
+
+    def testAvailableCA(self):
+        setUp()
+        setupZCML()
+        self.assertEqual(self.func(), True)
+
+    def testDecoratorLoadsZCMLCallable(self):
+        f = temporaryPlacelessSetUp(self.func, required_zcml=setupZCML)
+        self.assertEqual(f(), True)
+
+    def testDecoratorLoadsZCMLIterable(self):
+        f = temporaryPlacelessSetUp(self.func, required_zcml=(setupZCML,))
+        self.assertEqual(f(), True)
+
+    def testPlacelessFlagDisablesDecoration(self):
+        f = temporaryPlacelessSetUp(self.func, placeless_available=False, required_zcml=setupZCML)
+        self.assertRaises(TypeError, f)
+
+    def testDecoratedFuncLoadsZCMLCallable(self):
+        f = temporaryPlacelessSetUp(self.func)
+        self.assertEqual(f(required_zcml=setupZCML), True)
+
+    def testDecoratedFuncLoadsZCMLIterable(self):
+        f = temporaryPlacelessSetUp(self.func)
+        self.assertEqual(f(required_zcml=(setupZCML,)), True)
+
+
+def test_suite():
+    from unittest import TestSuite, makeSuite
+    suite = TestSuite()
+    if globals().get('IAdapted'):
+        suite.addTest(makeSuite(TestPlacelessSetUp))
+    return suite
+
+if __name__ == '__main__':
+    framework()
+


Property changes on: Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/testPlaceless.py
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/zopedoctest/__init__.py
===================================================================
--- Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/zopedoctest/__init__.py	2006-03-26 23:15:02 UTC (rev 66215)
+++ Zope/branches/Zope-2_8-branch/lib/python/Testing/ZopeTestCase/zopedoctest/__init__.py	2006-03-27 01:24:46 UTC (rev 66216)
@@ -16,5 +16,6 @@
 """
 
 from zope.testing.doctest import *
+from zope.testing.doctest import _normalize_module
 from functional import *
 



More information about the Checkins mailing list