Log message for revision 69707: applying layers patch to 2.10-layer Changed: U Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/ZopeLite.py U Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/ZopeTestCase.py U Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/__init__.py U Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/base.py A Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/layer.py U Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/placeless.py U Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/sandbox.py U Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/utils.py U Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/zopedoctest/__init__.py U Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/zopedoctest/functional.py A Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/zopedoctest/tests.py
-=- Modified: Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/ZopeLite.py =================================================================== --- Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/ZopeLite.py 2006-08-20 20:03:52 UTC (rev 69706) +++ Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/ZopeLite.py 2006-08-20 20:13:01 UTC (rev 69707) @@ -26,6 +26,7 @@ """ import os, sys, time +from utils import hasProduct, _print # Allow code to tell it is run by the test framework os.environ['ZOPETESTCASE'] = '1' @@ -36,11 +37,6 @@ # Shut up if we are not in control of the import process _quiet = sys.modules.has_key('Zope2') -def _print(msg): - '''Writes 'msg' to stderr and flushes the stream.''' - sys.stderr.write(msg) - sys.stderr.flush() - def _write(msg): '''Writes 'msg' to stderr if not _quiet.''' if not _quiet: @@ -139,10 +135,6 @@ _theApp = Zope2.app() _installedProducts = {} -def hasProduct(name): - '''Checks if a product can be found along Products.__path__''' - return name in [n[1] for n in get_products()] - def installProduct(name, quiet=0): '''Installs a Zope product.''' start = time.time() Modified: Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/ZopeTestCase.py =================================================================== --- Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/ZopeTestCase.py 2006-08-20 20:03:52 UTC (rev 69706) +++ Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/ZopeTestCase.py 2006-08-20 20:13:01 UTC (rev 69707) @@ -29,6 +29,7 @@ import interfaces import utils import connections +import layer from AccessControl import getSecurityManager from AccessControl.SecurityManagement import newSecurityManager @@ -51,6 +52,8 @@ _setup_fixture = 1 + layer = layer.Zope2Layer + def _setup(self): '''Sets up the fixture. Framework authors may override. Modified: Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/__init__.py =================================================================== --- Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/__init__.py 2006-08-20 20:03:52 UTC (rev 69706) +++ Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/__init__.py 2006-08-20 20:13:01 UTC (rev 69707) @@ -15,12 +15,12 @@ $Id$ """ -import ZopeLite as Zope2 import utils -from ZopeLite import hasProduct -from ZopeLite import installProduct -from ZopeLite import _print +from utils import hasProduct +from layer import installProduct +from utils import _print +from utils import setAllLayers from ZopeTestCase import folder_name from ZopeTestCase import user_name @@ -49,9 +49,10 @@ from zopedoctest import FunctionalDocTestSuite from zopedoctest import FunctionalDocFileSuite +from layer import ZopeLiteLayer +from layer import Zope2Layer + import zopedoctest as doctest import transaction import placeless -Zope = Zope2 - Modified: Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/base.py =================================================================== --- Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/base.py 2006-08-20 20:03:52 UTC (rev 69706) +++ Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/base.py 2006-08-20 20:13:01 UTC (rev 69707) @@ -15,7 +15,6 @@ $Id$ """ -import ZopeLite as Zope2 import unittest import transaction import profiler @@ -25,10 +24,9 @@ from AccessControl.SecurityManagement import noSecurityManager - - def app(): '''Opens a ZODB connection and returns the app object.''' + import ZopeLite as Zope2 app = Zope2.app() app = utils.makerequest(app) connections.register(app) Added: Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/layer.py =================================================================== --- Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/layer.py 2006-08-20 20:03:52 UTC (rev 69706) +++ Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/layer.py 2006-08-20 20:13:01 UTC (rev 69707) @@ -0,0 +1,54 @@ +############################################################################## +# +# 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. +# +############################################################################## +""" +layer support for ZopeTestCase + +$Id: $ +""" +import os +from utils import setDebugMode + +class ZopeLiteLayer: + @classmethod + def setUp(cls): + import ZopeLite + + @classmethod + def tearDown(cls): + raise NotImplementedError + +# products to install +_products=[] + +# setup functions +_z2_callables=[] +class Zope2Layer(ZopeLiteLayer): + """ stacks upon ZopeLiteLayer and handles products installs """ + @classmethod + def setUp(cls): + import ZopeLite as Zope2 + install = Zope2.installProduct + + [install(name, quiet=quiet) \ + for name, quiet in _products] + + [func(*args, **kw) for func, args, kw in _z2_callables] + + @classmethod + def tearDown(cls): + raise NotImplementedError + + +def installProduct(name, quiet=0): + if not (name, quiet) in _products: + _products.append((name, quiet)) Modified: Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/placeless.py =================================================================== --- Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/placeless.py 2006-08-20 20:03:52 UTC (rev 69706) +++ Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/placeless.py 2006-08-20 20:13:01 UTC (rev 69707) @@ -44,9 +44,6 @@ 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'): Modified: Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/sandbox.py =================================================================== --- Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/sandbox.py 2006-08-20 20:03:52 UTC (rev 69706) +++ Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/sandbox.py 2006-08-20 20:13:01 UTC (rev 69707) @@ -14,14 +14,11 @@ $Id$ """ - -import ZopeLite as Zope2 import transaction import base import utils import connections - class Sandboxed: '''Derive from this class and an xTestCase to make each test run in its own ZODB sandbox:: @@ -32,6 +29,7 @@ def _app(self): '''Returns the app object for a test.''' + import ZopeLite as Zope2 app = Zope2.app(Zope2.sandbox().open()) AppZapper().set(app) app = utils.makerequest(app) Modified: Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/utils.py =================================================================== --- Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/utils.py 2006-08-20 20:03:52 UTC (rev 69706) +++ Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/utils.py 2006-08-20 20:13:01 UTC (rev 69707) @@ -24,15 +24,46 @@ import random import transaction +def appcall(function, *args, **kw): + '''Calls a function passing 'app' as first argument.''' + from base import app, close + app = app() + args = (app,) + args + try: + return function(*args, **kw) + finally: + transaction.abort() + close(app) + +def deferToZ2Layer(function): + ''' + decorator assumes following: + + * function only takes one argument: app + + * if app is not passed in, function should be deferred + + deferral queues execution of the function to the setup call of + Testing.ZopeTestCase.layer.Zope2Layer + ''' + def wrapped(*args, **kwargs): + if args or kwargs.get('app', None): + return function(*args, **kwargs) + else: + import layer + def curryAppCall(*args, **kwargs): + return appcall(function, *args, **kwargs) + return layer._z2_callables.append((curryAppCall, args, kwargs)) + return wrapped + + [EMAIL PROTECTED] def setupCoreSessions(app=None): '''Sets up the session_data_manager e.a.''' from Acquisition import aq_base commit = 0 - if app is None: - return appcall(setupCoreSessions) - if not hasattr(app, 'temp_folder'): from Products.TemporaryFolder.TemporaryFolder import MountedTemporaryFolder tf = MountedTemporaryFolder('temp_folder', 'Temporary Folder') @@ -67,11 +98,9 @@ if commit: transaction.commit() - [EMAIL PROTECTED] def setupZGlobals(app=None): '''Sets up the ZGlobals BTree required by ZClasses.''' - if app is None: - return appcall(setupZGlobals) root = app._p_jar.root() if not root.has_key('ZGlobals'): @@ -79,11 +108,9 @@ root['ZGlobals'] = OOBTree() transaction.commit() - [EMAIL PROTECTED] def setupSiteErrorLog(app=None): '''Sets up the error_log object required by ZPublisher.''' - if app is None: - return appcall(setupSiteErrorLog) if not hasattr(app, 'error_log'): try: @@ -124,7 +151,6 @@ time.sleep(0.1) # Sandor Palfy return _Z2HOST, _Z2PORT - def makerequest(app, stdout=sys.stdout): '''Wraps the app into a fresh REQUEST.''' from Testing.makerequest import makerequest as _makerequest @@ -134,19 +160,6 @@ environ['REQUEST_METHOD'] = 'GET' return _makerequest(app, stdout=stdout, environ=environ) - -def appcall(function, *args, **kw): - '''Calls a function passing 'app' as first argument.''' - from base import app, close - app = app() - args = (app,) + args - try: - return function(*args, **kw) - finally: - transaction.abort() - close(app) - - def makelist(arg): '''Turns arg into a list. Where arg may be list, tuple, or string. @@ -159,7 +172,33 @@ return filter(None, [arg]) raise ValueError('Argument must be list, tuple, or string') +def hasProduct(name): + '''Checks if a product can be found along Products.__path__''' + from OFS.Application import get_products + return name in [n[1] for n in get_products()] +def _print(msg): + '''Writes 'msg' to stderr and flushes the stream.''' + sys.stderr.write(msg) + sys.stderr.flush() + +def setDebugMode(mode): + ''' + Allows manual setting of Five's inspection of debug mode to allow for + zcml to fail meaningfully + ''' + import Products.Five.fiveconfigure as fc + fc.debug_mode=mode + +def setAllLayers(suite, newlayer): + ''' + helper function that iterates through all the subsuites in a + suite, resetting their layer to @param layer: the desired layer + class + ''' + [setattr(subsuite, 'layer', newlayer) for subsuite in suite] + return suite + __all__ = [ 'setupCoreSessions', 'setupSiteErrorLog', @@ -169,5 +208,9 @@ 'appcall', 'makerequest', 'makelist', + 'hasProduct', + 'setDebugMode', + '_print', + 'setAllLayers' ] Modified: Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/zopedoctest/__init__.py =================================================================== --- Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/zopedoctest/__init__.py 2006-08-20 20:03:52 UTC (rev 69706) +++ Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/zopedoctest/__init__.py 2006-08-20 20:13:01 UTC (rev 69707) @@ -18,4 +18,3 @@ from zope.testing.doctest import * from zope.testing.doctest import _normalize_module from functional import * - Modified: Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/zopedoctest/functional.py =================================================================== --- Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/zopedoctest/functional.py 2006-08-20 20:03:52 UTC (rev 69706) +++ Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/zopedoctest/functional.py 2006-08-20 20:13:01 UTC (rev 69707) @@ -298,23 +298,34 @@ | doctest.REPORT_NDIFF | doctest.NORMALIZE_WHITESPACE) +from Testing.ZopeTestCase.layer import Zope2Layer +def setlayer(layer): + def wrapfactory(factory): + def wrapper(*args, **kwargs): + suite = factory(*args, **kwargs) + suite.layer=layer + return suite + return wrapper + return wrapfactory + [EMAIL PROTECTED](Zope2Layer) def ZopeDocTestSuite(module=None, **kw): module = doctest._normalize_module(module) return ZopeSuiteFactory(module, **kw).doctestsuite() - [EMAIL PROTECTED](Zope2Layer) def ZopeDocFileSuite(*paths, **kw): if kw.get('module_relative', True): kw['package'] = doctest._normalize_module(kw.get('package')) return ZopeSuiteFactory(*paths, **kw).docfilesuite() - [EMAIL PROTECTED](Zope2Layer) def FunctionalDocTestSuite(module=None, **kw): module = doctest._normalize_module(module) return FunctionalSuiteFactory(module, **kw).doctestsuite() - [EMAIL PROTECTED](Zope2Layer) def FunctionalDocFileSuite(*paths, **kw): if kw.get('module_relative', True): kw['package'] = doctest._normalize_module(kw.get('package')) Added: Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/zopedoctest/tests.py =================================================================== --- Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/zopedoctest/tests.py 2006-08-20 20:03:52 UTC (rev 69706) +++ Zope/branches/whitmo-2.10-layers/lib/python/Testing/ZopeTestCase/zopedoctest/tests.py 2006-08-20 20:13:01 UTC (rev 69707) @@ -0,0 +1,15 @@ +import os, sys +import unittest +suite = unittest.TestSuite() + +def test_suite(): + names = os.listdir(os.path.dirname(__file__)) + tests = [x for x in names \ + if x.startswith('test') and x.endswith('.py') and not x == 'tests.py'] + + for test in tests: + Testing = __import__("Testing.ZopeTestCase.zopedoctest." + test[:-3]) + testmodule = getattr(Testing.ZopeTestCase.zopedoctest, test[:-3]) + if hasattr(testmodule, 'test_suite'): + suite.addTest(testmodule.test_suite()) + return suite _______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins