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

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

-=-
Modified: Zope/branches/2.9/lib/python/Testing/ZopeTestCase/__init__.py
===================================================================
--- Zope/branches/2.9/lib/python/Testing/ZopeTestCase/__init__.py       
2006-03-27 01:26:56 UTC (rev 66217)
+++ Zope/branches/2.9/lib/python/Testing/ZopeTestCase/__init__.py       
2006-03-27 01:29:02 UTC (rev 66218)
@@ -51,6 +51,7 @@
 
 import zopedoctest as doctest
 import transaction
+import placeless
 
 Zope = Zope2
 

Modified: Zope/branches/2.9/lib/python/Testing/ZopeTestCase/base.py
===================================================================
--- Zope/branches/2.9/lib/python/Testing/ZopeTestCase/base.py   2006-03-27 
01:26:56 UTC (rev 66217)
+++ Zope/branches/2.9/lib/python/Testing/ZopeTestCase/base.py   2006-03-27 
01:29:02 UTC (rev 66218)
@@ -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/2.9/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt
===================================================================
--- Zope/branches/2.9/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt   
2006-03-27 01:26:56 UTC (rev 66217)
+++ Zope/branches/2.9/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt   
2006-03-27 01:29:02 UTC (rev 66218)
@@ -1,4 +1,4 @@
-Unreleased
+2.9 edition
 - transaction.commit(1) is deprecated in favor of transaction.savepoint().
 - Don't break if Python distros ship without profile support (Debian, Ubuntu).
 - Functional.publish() would hang if it got a request_method argument other
@@ -8,6 +8,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/2.9/lib/python/Testing/ZopeTestCase/placeless.py
===================================================================
--- Zope/branches/2.9/lib/python/Testing/ZopeTestCase/placeless.py      
2006-03-27 01:26:56 UTC (rev 66217)
+++ Zope/branches/2.9/lib/python/Testing/ZopeTestCase/placeless.py      
2006-03-27 01:29:02 UTC (rev 66218)
@@ -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$
+"""
+
+from zope.app.testing.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/2.9/lib/python/Testing/ZopeTestCase/placeless.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: Zope/branches/2.9/lib/python/Testing/ZopeTestCase/testPlaceless.py
===================================================================
--- Zope/branches/2.9/lib/python/Testing/ZopeTestCase/testPlaceless.py  
2006-03-27 01:26:56 UTC (rev 66217)
+++ Zope/branches/2.9/lib/python/Testing/ZopeTestCase/testPlaceless.py  
2006-03-27 01:29:02 UTC (rev 66218)
@@ -0,0 +1,97 @@
+##############################################################################
+#
+# 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
+from Products.Five.tests.adapters import IAdapted
+from Products.Five.tests.adapters import Adaptable
+
+
+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()
+    suite.addTest(makeSuite(TestPlacelessSetUp))
+    return suite
+
+if __name__ == '__main__':
+    framework()
+


Property changes on: 
Zope/branches/2.9/lib/python/Testing/ZopeTestCase/testPlaceless.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: 
Zope/branches/2.9/lib/python/Testing/ZopeTestCase/zopedoctest/__init__.py
===================================================================
--- Zope/branches/2.9/lib/python/Testing/ZopeTestCase/zopedoctest/__init__.py   
2006-03-27 01:26:56 UTC (rev 66217)
+++ Zope/branches/2.9/lib/python/Testing/ZopeTestCase/zopedoctest/__init__.py   
2006-03-27 01:29:02 UTC (rev 66218)
@@ -16,5 +16,6 @@
 """
 
 from zope.testing.doctest import *
+from zope.testing.doctest import _normalize_module
 from functional import *
 

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to