[Checkins] SVN: z3c.testing/tags/0.3.0/ Tag 0.3.0

Dan Korostelev nadako at gmail.com
Sun Feb 1 13:23:20 EST 2009


Log message for revision 95903:
  Tag 0.3.0

Changed:
  A   z3c.testing/tags/0.3.0/
  D   z3c.testing/tags/0.3.0/CHANGES.txt
  A   z3c.testing/tags/0.3.0/CHANGES.txt
  U   z3c.testing/tags/0.3.0/README.txt
  D   z3c.testing/tags/0.3.0/setup.py
  A   z3c.testing/tags/0.3.0/setup.py
  D   z3c.testing/tags/0.3.0/src/z3c/testing/app.py
  A   z3c.testing/tags/0.3.0/src/z3c/testing/app.py
  D   z3c.testing/tags/0.3.0/src/z3c/testing/generation.py
  A   z3c.testing/tags/0.3.0/src/z3c/testing/generation.py
  D   z3c.testing/tags/0.3.0/src/z3c/testing/layer.py
  A   z3c.testing/tags/0.3.0/src/z3c/testing/layer.py

-=-
Deleted: z3c.testing/tags/0.3.0/CHANGES.txt
===================================================================
--- z3c.testing/trunk/CHANGES.txt	2009-02-01 17:52:49 UTC (rev 95901)
+++ z3c.testing/tags/0.3.0/CHANGES.txt	2009-02-01 18:23:19 UTC (rev 95903)
@@ -1,19 +0,0 @@
-=======
-CHANGES
-=======
-
-0.2.0 (2007-10-31)
-------------------
-
-- Fix pacakge data.
-
-- Move functional tests to tests.
-
-- Remove deprecation warning.
-
-0.1.1b1 (2007-06-21)
---------------------
-
-- make ``z3c`` a namespace
-
-- prevent ``ConnectionStateError`` in layer after ``appsetup`` is run in layer

Copied: z3c.testing/tags/0.3.0/CHANGES.txt (from rev 95902, z3c.testing/trunk/CHANGES.txt)
===================================================================
--- z3c.testing/tags/0.3.0/CHANGES.txt	                        (rev 0)
+++ z3c.testing/tags/0.3.0/CHANGES.txt	2009-02-01 18:23:19 UTC (rev 95903)
@@ -0,0 +1,25 @@
+=======
+CHANGES
+=======
+
+0.3.0 (2009-02-01)
+------------------
+
+- Use ``zope.container`` instead of ``zope.app.container``
+- Use ``zope.site`` instead of ``zope.app.component``
+
+0.2.0 (2007-10-31)
+------------------
+
+- Fix pacakge data.
+
+- Move functional tests to tests.
+
+- Remove deprecation warning.
+
+0.1.1b1 (2007-06-21)
+--------------------
+
+- make ``z3c`` a namespace
+
+- prevent ``ConnectionStateError`` in layer after ``appsetup`` is run in layer

Modified: z3c.testing/tags/0.3.0/README.txt
===================================================================
--- z3c.testing/trunk/README.txt	2009-02-01 17:52:49 UTC (rev 95901)
+++ z3c.testing/tags/0.3.0/README.txt	2009-02-01 18:23:19 UTC (rev 95903)
@@ -1,4 +1,4 @@
-This package provides a collection of high-lvel test setups for unit and
+This package provides a collection of high-level test setups for unit and
 functional testing. In particular, it provides a testing layer that can use an
 existing, pre-populated database as a starting point, which speeds up the test
 setup phase for large testing data sets.

Deleted: z3c.testing/tags/0.3.0/setup.py
===================================================================
--- z3c.testing/trunk/setup.py	2009-02-01 17:52:49 UTC (rev 95901)
+++ z3c.testing/tags/0.3.0/setup.py	2009-02-01 18:23:19 UTC (rev 95903)
@@ -1,70 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2007 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.
-#
-##############################################################################
-"""Setup for z3c.viewlet package
-
-$Id$
-"""
-import os
-from setuptools import setup, find_packages
-
-def read(*rnames):
-    return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
-
-setup(name='z3c.testing',
-      version = '0.3.0',
-      author='Zope Corporation and Contributors',
-      author_email='zope3-dev at zope.org',
-      description='High-level Testing Support',
-      long_description=(
-          read('README.txt')
-          + '\n\n' +
-          read('CHANGES.txt')
-          ),
-      keywords = "zope3 testing layer zodb",
-      classifiers = [
-          'Development Status :: 5 - Production/Stable',
-          'Environment :: Web Environment',
-          'Intended Audience :: Developers',
-          'License :: OSI Approved :: Zope Public License',
-          'Programming Language :: Python',
-          'Natural Language :: English',
-          'Operating System :: OS Independent',
-          'Topic :: Internet :: WWW/HTTP',
-          'Framework :: Zope3'],
-      url='http://cheeseshop.python.org/pypi/z3c.testing',
-      license='ZPL 2.1',
-      packages=find_packages('src'),
-      package_dir = {'': 'src'},
-      namespace_packages=['z3c'],
-      extras_require=dict(test=['zope.app.zcmlfiles',
-                                'zope.testbrowser',
-                                'zope.securitypolicy',
-                                'zope.app.securitypolicy',
-                                ]),
-      install_requires = ['setuptools',
-                          'ZODB3',
-                          'zope.app.appsetup',
-                          'zope.app.container',
-                          'zope.app.folder',
-                          'zope.app.publication',
-                          'zope.app.security',
-                          'zope.app.testing',
-                          'zope.component',
-                          'zope.configuration',
-                          'zope.interface',
-                          'zope.testing',
-                          ],
-      include_package_data = True,
-      zip_safe = False,
-      )

Copied: z3c.testing/tags/0.3.0/setup.py (from rev 95902, z3c.testing/trunk/setup.py)
===================================================================
--- z3c.testing/tags/0.3.0/setup.py	                        (rev 0)
+++ z3c.testing/tags/0.3.0/setup.py	2009-02-01 18:23:19 UTC (rev 95903)
@@ -0,0 +1,70 @@
+##############################################################################
+#
+# Copyright (c) 2007 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.
+#
+##############################################################################
+"""Setup for z3c.testing package
+
+$Id$
+"""
+import os
+from setuptools import setup, find_packages
+
+def read(*rnames):
+    return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+setup(name='z3c.testing',
+      version = '0.3.0',
+      author='Zope Corporation and Contributors',
+      author_email='zope-dev at zope.org',
+      description='High-level Testing Support',
+      long_description=(
+          read('README.txt')
+          + '\n\n' +
+          read('CHANGES.txt')
+          ),
+      keywords = "zope3 testing layer zodb",
+      classifiers = [
+          'Development Status :: 5 - Production/Stable',
+          'Environment :: Web Environment',
+          'Intended Audience :: Developers',
+          'License :: OSI Approved :: Zope Public License',
+          'Programming Language :: Python',
+          'Natural Language :: English',
+          'Operating System :: OS Independent',
+          'Topic :: Internet :: WWW/HTTP',
+          'Framework :: Zope3'],
+      url='http://pypi.python.org/pypi/z3c.testing',
+      license='ZPL 2.1',
+      packages=find_packages('src'),
+      package_dir = {'': 'src'},
+      namespace_packages=['z3c'],
+      extras_require=dict(test=['zope.app.zcmlfiles',
+                                'zope.testbrowser',
+                                'zope.securitypolicy',
+                                'zope.app.securitypolicy',
+                                ]),
+      install_requires = ['setuptools',
+                          'ZODB3',
+                          'zope.app.appsetup',
+                          'zope.app.publication',
+                          'zope.app.security',
+                          'zope.app.testing',
+                          'zope.container',
+                          'zope.site',
+                          'zope.component',
+                          'zope.configuration',
+                          'zope.interface',
+                          'zope.testing',
+                          ],
+      include_package_data = True,
+      zip_safe = False,
+      )

Deleted: z3c.testing/tags/0.3.0/src/z3c/testing/app.py
===================================================================
--- z3c.testing/trunk/src/z3c/testing/app.py	2009-02-01 17:52:49 UTC (rev 95901)
+++ z3c.testing/tags/0.3.0/src/z3c/testing/app.py	2009-02-01 18:23:19 UTC (rev 95903)
@@ -1,104 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2005 Zope Foundation 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.
-#
-##############################################################################
-"""
-$Id$
-"""
-
-import unittest
-
-
-###############################################################################
-#
-# TestCase
-#
-###############################################################################
-marker_pos = object()
-marker_kws = object()
-
-class TestCase(unittest.TestCase):
-
-    def getTestInterface(self):
-        msg = 'Subclasses has to implement getTestInterface()'
-        raise NotImplementedError, msg
-
-    def getTestClass(self):
-        raise NotImplementedError, 'Subclasses has to implement getTestClass()'
-
-    def getTestPos(self):
-        return marker_pos
-
-    def getTestKws(self):
-        return marker_kws
-    
-    def makeTestObject(self, object=None, *pos, **kws):
-        # provide default positional or keyword arguments
-        if self.getTestPos() is not marker_pos and not pos:
-            pos = self.getTestPos()
-
-        if self.getTestKws() is not marker_kws and not kws:
-            kws = self.getTestKws()
-       
-        testclass = self.getTestClass()
-
-        if object is None:
-            # a class instance itself is the object to be tested.         
-            return testclass(*pos, **kws)
-
-        else:
-            # an adapted instance is the object to be tested. 
-            return testclass(object, *pos, **kws)
-
-
-###############################################################################
-#
-# Public Base Tests
-#
-###############################################################################
-from zope.interface.verify import verifyObject
-from z3c.testing.verify import verifyClass
-
-
-class InterfaceBaseTest(TestCase):
-    """Base test for IContainer including interface test."""
-
-    def test_verifyClass(self):
-        # class test
-        self.assert_(verifyClass(self.getTestInterface(), self.getTestClass())) 
-
-    def test_verifyObject(self):
-        # object test
-        self.assert_(verifyObject(self.getTestInterface(), 
-            self.makeTestObject()))
-
-
-###############################################################################
-#
-# IContainer Base Tests
-#
-###############################################################################
-
-from zope.app.container.tests.test_icontainer import BaseTestIContainer as BTIC
-from zope.app.container.tests.test_icontainer import DefaultTestData
-
-
-class BaseTestIContainer(InterfaceBaseTest, BTIC):
-
-    def makeTestData(self):
-        return DefaultTestData()
-
-    def getUnknownKey(self):
-        return '10'
-
-    def getBadKeyTypes(self):
-        return [None, ['foo'], 1, '\xf3abc']

Copied: z3c.testing/tags/0.3.0/src/z3c/testing/app.py (from rev 95902, z3c.testing/trunk/src/z3c/testing/app.py)
===================================================================
--- z3c.testing/tags/0.3.0/src/z3c/testing/app.py	                        (rev 0)
+++ z3c.testing/tags/0.3.0/src/z3c/testing/app.py	2009-02-01 18:23:19 UTC (rev 95903)
@@ -0,0 +1,104 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Foundation 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.
+#
+##############################################################################
+"""
+$Id$
+"""
+
+import unittest
+
+
+###############################################################################
+#
+# TestCase
+#
+###############################################################################
+marker_pos = object()
+marker_kws = object()
+
+class TestCase(unittest.TestCase):
+
+    def getTestInterface(self):
+        msg = 'Subclasses has to implement getTestInterface()'
+        raise NotImplementedError, msg
+
+    def getTestClass(self):
+        raise NotImplementedError, 'Subclasses has to implement getTestClass()'
+
+    def getTestPos(self):
+        return marker_pos
+
+    def getTestKws(self):
+        return marker_kws
+    
+    def makeTestObject(self, object=None, *pos, **kws):
+        # provide default positional or keyword arguments
+        if self.getTestPos() is not marker_pos and not pos:
+            pos = self.getTestPos()
+
+        if self.getTestKws() is not marker_kws and not kws:
+            kws = self.getTestKws()
+       
+        testclass = self.getTestClass()
+
+        if object is None:
+            # a class instance itself is the object to be tested.         
+            return testclass(*pos, **kws)
+
+        else:
+            # an adapted instance is the object to be tested. 
+            return testclass(object, *pos, **kws)
+
+
+###############################################################################
+#
+# Public Base Tests
+#
+###############################################################################
+from zope.interface.verify import verifyObject
+from z3c.testing.verify import verifyClass
+
+
+class InterfaceBaseTest(TestCase):
+    """Base test for IContainer including interface test."""
+
+    def test_verifyClass(self):
+        # class test
+        self.assert_(verifyClass(self.getTestInterface(), self.getTestClass())) 
+
+    def test_verifyObject(self):
+        # object test
+        self.assert_(verifyObject(self.getTestInterface(), 
+            self.makeTestObject()))
+
+
+###############################################################################
+#
+# IContainer Base Tests
+#
+###############################################################################
+
+from zope.container.tests.test_icontainer import BaseTestIContainer as BTIC
+from zope.container.tests.test_icontainer import DefaultTestData
+
+
+class BaseTestIContainer(InterfaceBaseTest, BTIC):
+
+    def makeTestData(self):
+        return DefaultTestData()
+
+    def getUnknownKey(self):
+        return '10'
+
+    def getBadKeyTypes(self):
+        return [None, ['foo'], 1, '\xf3abc']

Deleted: z3c.testing/tags/0.3.0/src/z3c/testing/generation.py
===================================================================
--- z3c.testing/trunk/src/z3c/testing/generation.py	2009-02-01 17:52:49 UTC (rev 95901)
+++ z3c.testing/tags/0.3.0/src/z3c/testing/generation.py	2009-02-01 18:23:19 UTC (rev 95903)
@@ -1,89 +0,0 @@
-###############################################################################
-#
-# Copyright 2006 by refline (Schweiz) AG, CH-5630 Muri
-#
-###############################################################################
-"""
-$Id$
-"""
-
-import os
-
-from ZODB.FileStorage import FileStorage
-from ZODB.DB import DB
-from ZODB.DemoStorage import DemoStorage
-
-from zope.testing import doctest
-from zope.app.publication.zopepublication import ZopePublication
-from zope.app.testing import setup
-from zope.app.folder.folder import rootFolder
-
-
-###############################################################################
-#
-# Test component
-#
-###############################################################################
-
-class ContextStub(object):
-    """Stub for the context argument passed to evolve scripts.
-
-    >>> from zope.app.zopeappgenerations import getRootFolder
-    >>> context = ContextStub()
-    >>> getRootFolder(context) is context.root_folder
-    True
-
-    """
-
-    class ConnectionStub(object):
-        def __init__(self, root_folder, db):
-            self.root_folder = root_folder
-            self.db = db
-
-        def root(self):
-            return {ZopePublication.root_name: self.root_folder}
-
-        @property
-        def _storage(self):
-            return self.db._storage._base
-
-        def get(self, oid):
-            return self.db.open().get(oid)
-
-    def __init__(self, rootFolder, db):
-        self.root_folder = rootFolder
-        self.connection = self.ConnectionStub(self.root_folder, db)
-
-
-def getDBRoot(db):
-    """Returns the Zope root folder."""
-    connection = db.open()
-    root = connection.root()
-    return root[ZopePublication.root_name]
-
-
-def getDB(filename, package=None):
-    """Returns a DB by it's path."""
-    if package is not None:
-        filename = doctest._module_relative_path(package, filename)
-        package = package.__file__
-    else:
-        package = __file__
-    filename = os.path.join(os.path.dirname(package), filename)
-    fileStorage = FileStorage(filename)
-    storage = DemoStorage("Demo Storage", fileStorage)
-    return DB(storage)
-
-
-###############################################################################
-#
-# Test setup
-#
-###############################################################################
-
-def setUpGeneration(test):
-    setup.placefulSetUp()
-
-
-def tearDownGeneration(test):
-    setup.placefulTearDown()

Copied: z3c.testing/tags/0.3.0/src/z3c/testing/generation.py (from rev 95902, z3c.testing/trunk/src/z3c/testing/generation.py)
===================================================================
--- z3c.testing/tags/0.3.0/src/z3c/testing/generation.py	                        (rev 0)
+++ z3c.testing/tags/0.3.0/src/z3c/testing/generation.py	2009-02-01 18:23:19 UTC (rev 95903)
@@ -0,0 +1,89 @@
+###############################################################################
+#
+# Copyright 2006 by refline (Schweiz) AG, CH-5630 Muri
+#
+###############################################################################
+"""
+$Id$
+"""
+
+import os
+
+from ZODB.FileStorage import FileStorage
+from ZODB.DB import DB
+from ZODB.DemoStorage import DemoStorage
+
+from zope.testing import doctest
+from zope.app.publication.zopepublication import ZopePublication
+from zope.app.testing import setup
+from zope.site.folder import rootFolder
+
+
+###############################################################################
+#
+# Test component
+#
+###############################################################################
+
+class ContextStub(object):
+    """Stub for the context argument passed to evolve scripts.
+
+    >>> from zope.app.zopeappgenerations import getRootFolder
+    >>> context = ContextStub()
+    >>> getRootFolder(context) is context.root_folder
+    True
+
+    """
+
+    class ConnectionStub(object):
+        def __init__(self, root_folder, db):
+            self.root_folder = root_folder
+            self.db = db
+
+        def root(self):
+            return {ZopePublication.root_name: self.root_folder}
+
+        @property
+        def _storage(self):
+            return self.db._storage._base
+
+        def get(self, oid):
+            return self.db.open().get(oid)
+
+    def __init__(self, rootFolder, db):
+        self.root_folder = rootFolder
+        self.connection = self.ConnectionStub(self.root_folder, db)
+
+
+def getDBRoot(db):
+    """Returns the Zope root folder."""
+    connection = db.open()
+    root = connection.root()
+    return root[ZopePublication.root_name]
+
+
+def getDB(filename, package=None):
+    """Returns a DB by it's path."""
+    if package is not None:
+        filename = doctest._module_relative_path(package, filename)
+        package = package.__file__
+    else:
+        package = __file__
+    filename = os.path.join(os.path.dirname(package), filename)
+    fileStorage = FileStorage(filename)
+    storage = DemoStorage("Demo Storage", fileStorage)
+    return DB(storage)
+
+
+###############################################################################
+#
+# Test setup
+#
+###############################################################################
+
+def setUpGeneration(test):
+    setup.placefulSetUp()
+
+
+def tearDownGeneration(test):
+    setup.placefulTearDown()

Deleted: z3c.testing/tags/0.3.0/src/z3c/testing/layer.py
===================================================================
--- z3c.testing/trunk/src/z3c/testing/layer.py	2009-02-01 17:52:49 UTC (rev 95901)
+++ z3c.testing/tags/0.3.0/src/z3c/testing/layer.py	2009-02-01 18:23:19 UTC (rev 95903)
@@ -1,126 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2006 Lovely Systems 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.
-#
-##############################################################################
-"""A test layer to use a saved database.
-
-The testlayer creates a database using a configurator and uses the
-database for all tests.
-
-$Id$
-"""
-__docformat__ = "reStructuredText"
-
-import os
-import transaction
-import shutil
-from ZODB.FileStorage import FileStorage
-
-from zope.app.appsetup import database
-from zope.app.testing import functional
-from zope.app.publication.zopepublication import ZopePublication
-import sys
-from zope.app.component import hooks
-
-class BufferedDatabaseTestLayer(object):
-    """A test layer which creates a filestorage database.
-
-    The created database is later used without the need to run through the
-    setup again.
-    This speeds up functional tests.
-    """
-
-    __name__ = "BufferedTestLayer"
-    __bases__ = ()
-    path = None
-
-    def __init__(self, config_file=None, module=__module__,
-                 name="BufferedTestLayer", path=None, clean=False):
-        self.config_file = config_file or functional.Functional.config_file
-        self.__module__ = module
-        self.__name__ = name
-        self.path = path
-        self.dbDir = os.path.join(self.path,
-                                  'var_%s' % self.__module__)
-        if clean and os.path.isdir(self.dbDir):
-            shutil.rmtree(self.dbDir)
-
-    def setUpApplication(self, app):
-        # to be overridden by subclass
-        pass
-
-    def setUp(self):
-        if not os.path.exists(self.dbDir):
-            os.mkdir(self.dbDir)
-        filename = os.path.join(self.dbDir, 'TestData.fs')
-        fsetup = functional.FunctionalTestSetup(self.config_file)
-        self.original = fsetup.base_storage
-        if not os.path.exists(filename):
-
-            # Generate a new database from scratch and fill it
-            db = database(filename)
-            connection = db.open()
-            root = connection.root()
-            app = root[ZopePublication.root_name]
-            # store the site, because the connection gets closed
-            site = hooks.getSite()
-            self.setUpApplication(app)
-            transaction.commit()
-            connection.close()
-            db.close()
-            hooks.setSite(site)
-            
-        # sets up the db stuff normal
-        fsetup.setUp()
-        # replace the storage with our filestorage
-        fsetup.base_storage = FileStorage(filename)
-        # override close on this instance, so files dont get closed on
-        # setup/teardown of functionsetup
-        fsetup.base_storage.close = lambda : None
-
-    def tearDown(self):
-        fsetup = functional.FunctionalTestSetup(self.config_file)
-        # close the filestorage files now by calling the original
-        # close on our storage instance
-        FileStorage.close(fsetup.base_storage)
-        # replace the storage with the original, so functionalsetup
-        # can do what it wants with it
-        fsetup.base_storage = self.original
-        fsetup.tearDown()
-
-        #fsetup._config_file = False
-        #fsetup._database_names = None
-        #fsetup._init = False
-
-        fsetup.tearDownCompletely()
-
-
-def defineLayer(name, zcml=None, appSetUp=None, clean=False):
-    """Helper function for defining layers.
-
-    Defines a new buffered database layer
-
-    :name: the name of the layer in the module
-    :zcml: optional zcml file relative to package dir
-    :appSetUp: a callable which takes an application object as argument
-    :clean: if True the database directory is deleted on init
-    """
-    globals = sys._getframe(1).f_globals
-    if zcml is not None:
-        zcml = os.path.join(os.path.split(globals['__file__'])[0], zcml)
-    l = BufferedDatabaseTestLayer(
-        zcml, globals['__name__'], name,
-        path=os.path.dirname(globals['__file__']),
-        clean=clean)
-    if appSetUp is not None:
-        l.setUpApplication = appSetUp
-    globals[name] = l

Copied: z3c.testing/tags/0.3.0/src/z3c/testing/layer.py (from rev 95902, z3c.testing/trunk/src/z3c/testing/layer.py)
===================================================================
--- z3c.testing/tags/0.3.0/src/z3c/testing/layer.py	                        (rev 0)
+++ z3c.testing/tags/0.3.0/src/z3c/testing/layer.py	2009-02-01 18:23:19 UTC (rev 95903)
@@ -0,0 +1,126 @@
+##############################################################################
+#
+# Copyright (c) 2006 Lovely Systems 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.
+#
+##############################################################################
+"""A test layer to use a saved database.
+
+The testlayer creates a database using a configurator and uses the
+database for all tests.
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+import os
+import transaction
+import shutil
+from ZODB.FileStorage import FileStorage
+
+from zope.app.appsetup import database
+from zope.app.testing import functional
+from zope.app.publication.zopepublication import ZopePublication
+import sys
+from zope.site import hooks
+
+class BufferedDatabaseTestLayer(object):
+    """A test layer which creates a filestorage database.
+
+    The created database is later used without the need to run through the
+    setup again.
+    This speeds up functional tests.
+    """
+
+    __name__ = "BufferedTestLayer"
+    __bases__ = ()
+    path = None
+
+    def __init__(self, config_file=None, module=__module__,
+                 name="BufferedTestLayer", path=None, clean=False):
+        self.config_file = config_file or functional.Functional.config_file
+        self.__module__ = module
+        self.__name__ = name
+        self.path = path
+        self.dbDir = os.path.join(self.path,
+                                  'var_%s' % self.__module__)
+        if clean and os.path.isdir(self.dbDir):
+            shutil.rmtree(self.dbDir)
+
+    def setUpApplication(self, app):
+        # to be overridden by subclass
+        pass
+
+    def setUp(self):
+        if not os.path.exists(self.dbDir):
+            os.mkdir(self.dbDir)
+        filename = os.path.join(self.dbDir, 'TestData.fs')
+        fsetup = functional.FunctionalTestSetup(self.config_file)
+        self.original = fsetup.base_storage
+        if not os.path.exists(filename):
+
+            # Generate a new database from scratch and fill it
+            db = database(filename)
+            connection = db.open()
+            root = connection.root()
+            app = root[ZopePublication.root_name]
+            # store the site, because the connection gets closed
+            site = hooks.getSite()
+            self.setUpApplication(app)
+            transaction.commit()
+            connection.close()
+            db.close()
+            hooks.setSite(site)
+            
+        # sets up the db stuff normal
+        fsetup.setUp()
+        # replace the storage with our filestorage
+        fsetup.base_storage = FileStorage(filename)
+        # override close on this instance, so files dont get closed on
+        # setup/teardown of functionsetup
+        fsetup.base_storage.close = lambda : None
+
+    def tearDown(self):
+        fsetup = functional.FunctionalTestSetup(self.config_file)
+        # close the filestorage files now by calling the original
+        # close on our storage instance
+        FileStorage.close(fsetup.base_storage)
+        # replace the storage with the original, so functionalsetup
+        # can do what it wants with it
+        fsetup.base_storage = self.original
+        fsetup.tearDown()
+
+        #fsetup._config_file = False
+        #fsetup._database_names = None
+        #fsetup._init = False
+
+        fsetup.tearDownCompletely()
+
+
+def defineLayer(name, zcml=None, appSetUp=None, clean=False):
+    """Helper function for defining layers.
+
+    Defines a new buffered database layer
+
+    :name: the name of the layer in the module
+    :zcml: optional zcml file relative to package dir
+    :appSetUp: a callable which takes an application object as argument
+    :clean: if True the database directory is deleted on init
+    """
+    globals = sys._getframe(1).f_globals
+    if zcml is not None:
+        zcml = os.path.join(os.path.split(globals['__file__'])[0], zcml)
+    l = BufferedDatabaseTestLayer(
+        zcml, globals['__name__'], name,
+        path=os.path.dirname(globals['__file__']),
+        clean=clean)
+    if appSetUp is not None:
+        l.setUpApplication = appSetUp
+    globals[name] = l



More information about the Checkins mailing list