Commit 01b6f3b2 authored by Stefan H. Holek's avatar Stefan H. Holek

- Made base.TestCase a new-style class.

- Added placeless.py for Z3-style setup. Thanks to Whit Morriss.
parent 89307bda
......@@ -51,6 +51,7 @@ from zopedoctest import FunctionalDocFileSuite
import zopedoctest as doctest
import transaction
import placeless
Zope = Zope2
......@@ -40,7 +40,7 @@ def close(app):
class TestCase(profiler.Profiled, unittest.TestCase):
class TestCase(profiler.Profiled, unittest.TestCase, object):
'''Base test case for Zope testing
'''
......
Unreleased
Zope 2.10 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 @@ Unreleased
- 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
......
##############################################################################
#
# 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
##############################################################################
#
# 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()
......@@ -16,5 +16,6 @@ $Id$
"""
from zope.testing.doctest import *
from zope.testing.doctest import _normalize_module
from functional import *
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment