Commit f29ef98d authored by Stefan H. Holek's avatar Stefan H. Holek

Use a test_class to gain better control over fixture cleanup.

parent b36d4e11
...@@ -216,6 +216,7 @@ DB = Zope2.DB ...@@ -216,6 +216,7 @@ DB = Zope2.DB
configure = Zope2.configure configure = Zope2.configure
def startup(): pass def startup(): pass
Zope = Zope2 Zope = Zope2
active = _patched
# ZODB sandbox factory # ZODB sandbox factory
from ZODB.DemoStorage import DemoStorage from ZODB.DemoStorage import DemoStorage
......
...@@ -20,9 +20,12 @@ if __name__ == '__main__': ...@@ -20,9 +20,12 @@ if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py')) execfile(os.path.join(sys.path[0], 'framework.py'))
from unittest import TestSuite from unittest import TestSuite
from Testing.ZopeTestCase import FunctionalDocTestSuite from Testing import ZopeTestCase
from Testing.ZopeTestCase import ZopeLite
from Testing.ZopeTestCase import ZopeDocTestSuite
from Products.Five import zcml from Products.Five import zcml
from zope.testing import cleanup from zope.testing import cleanup
import Products
def testInstallPackage(): def testInstallPackage():
...@@ -31,15 +34,12 @@ def testInstallPackage(): ...@@ -31,15 +34,12 @@ def testInstallPackage():
>>> from Testing import ZopeTestCase >>> from Testing import ZopeTestCase
>>> from Products.Five import zcml >>> from Products.Five import zcml
>>> import sys, Products
Rig sys.path so testpackage can be imported
>>> saved = sys.path[:]
>>> sys.path.append(ZopeTestCase.__path__[0])
Register testpackage Register testpackage
>>> ZopeTestCase.hasPackage('testpackage')
False
>>> config = ''' >>> config = '''
... <configure ... <configure
... xmlns:five="http://namespaces.zope.org/five"> ... xmlns:five="http://namespaces.zope.org/five">
...@@ -48,19 +48,18 @@ def testInstallPackage(): ...@@ -48,19 +48,18 @@ def testInstallPackage():
... initialize="testpackage.initialize" ... initialize="testpackage.initialize"
... /> ... />
... </configure>''' ... </configure>'''
>>> ZopeTestCase.hasPackage('testpackage')
False
>>> zcml.load_string(config) >>> zcml.load_string(config)
The package is registered now
>>> ZopeTestCase.hasPackage('testpackage') >>> ZopeTestCase.hasPackage('testpackage')
True True
Not yet installed But not yet installed
>>> app = ZopeTestCase.app() >>> app = self._app()
>>> 'testpackage' in app.Control_Panel.Products.objectIds() >>> 'testpackage' in app.Control_Panel.Products.objectIds()
False False
>>> ZopeTestCase.close(app)
Install it Install it
...@@ -69,39 +68,54 @@ def testInstallPackage(): ...@@ -69,39 +68,54 @@ def testInstallPackage():
Now it shows up in Control_Panel Now it shows up in Control_Panel
>>> app = ZopeTestCase.app() >>> app = self._app()
>>> 'testpackage' in app.Control_Panel.Products.objectIds() >>> 'testpackage' in app.Control_Panel.Products.objectIds()
True True
>>> ZopeTestCase.close(app)
hasPackage still returns True hasPackage still returns True
>>> ZopeTestCase.hasPackage('testpackage') >>> ZopeTestCase.hasPackage('testpackage')
True True
Clean up A package is only installed once, subsequent calls to installPackage
are ignored:
>>> import testpackage >>> ZopeTestCase.installPackage('testpackage', quiet=True)
>>> Products._registered_packages.remove(testpackage)
>>> sys.path[:] = saved
""" """
def setUp(self): class TestClass(ZopeTestCase.FunctionalTestCase):
cleanup.cleanUp()
zcml._initialized = False def afterSetUp(self):
zcml.load_site() cleanup.cleanUp()
zcml._initialized = False
zcml.load_site()
self.saved = sys.path[:]
sys.path.append(ZopeTestCase.__path__[0])
def afterClear(self):
cleanup.cleanUp()
sys.path[:] = self.saved
registered = getattr(Products, '_registered_packages', None)
if registered is not None:
Products._registered_packages = [m for m in registered
if m.__name__ != 'testpackage']
def tearDown(self): to_initialize = getattr(Products, '_packages_to_initialize', None)
cleanup.cleanUp() if to_initialize is not None:
zcml._initialized = False Products._packages_to_initialize = [(m, f) for (m, f) in to_initialize
if m.__name__ != 'testpackage']
def test_suite(): def test_suite():
return TestSuite(( if ZopeLite.active:
# Must use functional because installPackage commits return TestSuite((
FunctionalDocTestSuite(setUp=setUp, tearDown=tearDown), ZopeDocTestSuite(test_class=TestClass),
)) ))
else:
return TestSuite()
if __name__ == '__main__': if __name__ == '__main__':
framework() framework()
......
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