~menesis/ubuntu/natty/zope.app.appsetup/natty

« back to all changes in this revision

Viewing changes to src/zope/app/appsetup/tests.py

  • Committer: Gediminas Paulauskas
  • Date: 2010-08-31 17:05:30 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: menesis@pov.lt-20100831170530-1kqlch6txq2pru8l
Tags: 3.14.0-0ubuntu1
* New upstream release.
* LICENSE.txt: add the license.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
##############################################################################
14
14
"""Bootstrap tests
15
15
 
16
 
$Id: tests.py 101171 2009-06-20 19:05:45Z icemac $
 
16
$Id: tests.py 108378 2010-01-21 18:59:23Z thefunny42 $
17
17
"""
18
18
import ZConfig
19
19
import os
36
36
from zope.app.publication.zopepublication import ZopePublication
37
37
from zope.site.site import LocalSiteManager
38
38
 
 
39
import zope.app.appsetup
39
40
from zope.app.appsetup.bootstrap import bootStrapSubscriber
40
41
from zope.app.appsetup.bootstrap import getInformationFromEvent, \
41
42
     ensureObject, ensureUtility
45
46
from zope.session.interfaces import IClientIdManager
46
47
from zope.session.interfaces import ISessionDataContainer
47
48
 
48
 
from zope.app.testing import placelesssetup
49
 
from zope.app.testing import setup
 
49
from zope.component.testlayer import ZCMLFileLayer
50
50
 
 
51
layer = ZCMLFileLayer(zope.app.appsetup)
51
52
 
52
53
class EventStub(object):
53
54
 
58
59
# TODO: some methods from the boostap module are not tested
59
60
#
60
61
 
61
 
class TestBootstrapSubscriber(placelesssetup.PlacelessSetup, unittest.TestCase):
 
62
class TestBootstrapSubscriber(unittest.TestCase):
 
63
 
 
64
    layer = layer
62
65
 
63
66
    def setUp(self):
64
 
        setup.placefulSetUp()
65
67
        self.db = DB()
66
68
 
67
69
    def tearDown(self):
68
70
        transaction.abort()
69
 
        setup.placefulTearDown()
70
71
        self.db.close()
71
72
 
72
73
    def createRootFolder(self):
230
231
        schema = ZConfig.loadSchema(url)
231
232
 
232
233
 
233
 
def bootstraptearDown(test):
234
 
    test.globs['db'].close()
235
 
 
236
 
 
237
 
def setUpDebug(test):
238
 
    placelesssetup.setUp(test)
239
 
    test.real_stderr = sys.stderr
240
 
    test.real_argv = list(sys.argv)
241
 
    test.olddir = os.getcwd()
242
 
    os.chdir(os.path.join(os.path.dirname(__file__), 'testdata'))
243
 
    from zope.security.management import endInteraction
244
 
    endInteraction()
245
 
 
246
 
 
247
 
def tearDownDebug(test):
248
 
    sys.stderr = test.real_stderr
249
 
    sys.argv[:] = test.real_argv
250
 
    if hasattr(sys, 'ps1'):
251
 
        del sys.ps1
252
 
    os.chdir(test.olddir)
253
 
    # make sure we don't leave environment variables that would cause
254
 
    # Python to open an interactive console
255
 
    if 'PYTHONINSPECT' in os.environ:
256
 
        del os.environ['PYTHONINSPECT']
257
 
    from zope.security.management import endInteraction
258
 
    endInteraction()
259
 
    placelesssetup.tearDown(test)
 
234
 
 
235
class DebugLayer(ZCMLFileLayer):
 
236
 
 
237
    def setUp(self):
 
238
        super(DebugLayer, self).setUp()
 
239
        self.stderr = sys.stderr
 
240
        self.argv = list(sys.argv)
 
241
        self.olddir = os.getcwd()
 
242
        os.chdir(os.path.join(os.path.dirname(__file__), 'testdata'))
 
243
        from zope.security.management import endInteraction
 
244
        endInteraction()
 
245
 
 
246
    def tearDown(self):
 
247
        sys.stderr = self.stderr
 
248
        sys.argv[:] = self.argv
 
249
        if hasattr(sys, 'ps1'):
 
250
            del sys.ps1
 
251
        os.chdir(self.olddir)
 
252
        # make sure we don't leave environment variables that would cause
 
253
        # Python to open an interactive console
 
254
        if 'PYTHONINSPECT' in os.environ:
 
255
            del os.environ['PYTHONINSPECT']
 
256
        from zope.security.management import endInteraction
 
257
        endInteraction()
 
258
        super(DebugLayer, self).tearDown()
260
259
 
261
260
 
262
261
def test_suite():
263
262
    suite = unittest.TestSuite()
264
263
    suite.addTest(unittest.makeSuite(TestBootstrapSubscriber))
265
264
    suite.addTest(unittest.makeSuite(TestConfigurationSchema))
266
 
    suite.addTest(doctest.DocTestSuite(
267
 
        'zope.app.appsetup.appsetup',
268
 
        setUp=placelesssetup.setUp, tearDown=placelesssetup.tearDown))
269
 
    suite.addTest(doctest.DocFileSuite(
270
 
        'bootstrap.txt', 'product.txt',
271
 
        setUp=placelesssetup.setUp, tearDown=placelesssetup.tearDown,
272
 
        ))
273
 
    suite.addTest(doctest.DocFileSuite(
274
 
        'debug.txt',
275
 
        setUp=setUpDebug, tearDown=tearDownDebug,
276
 
        ))
 
265
    for module in ['zope.app.appsetup.appsetup',]:
 
266
        test = doctest.DocTestSuite(module)
 
267
        test.layer = layer
 
268
        suite.addTest(test)
 
269
    for filename in ['bootstrap.txt', 'product.txt',]:
 
270
        test = doctest.DocFileSuite(filename)
 
271
        test.layer = layer
 
272
        suite.addTest(test)
 
273
 
 
274
    test = doctest.DocFileSuite('debug.txt')
 
275
    test.layer = DebugLayer(zope.app.appsetup)
 
276
    suite.addTest(test)
 
277
    suite.addTest(doctest.DocFileSuite(
 
278
        'testlayer.txt',
 
279
         optionflags=(doctest.ELLIPSIS +
 
280
                      doctest.NORMALIZE_WHITESPACE +
 
281
                      doctest.REPORT_NDIFF)))
 
282
 
277
283
    return suite
278
284
 
279
285
if __name__ == '__main__':