Commit 0d7f3cea authored by Stefan H. Holek's avatar Stefan H. Holek

Merged r69818:70069 from 2.10 branch.

Layer fix and version bump.
parents f852d30a 91537bfa
......@@ -12,6 +12,8 @@
- Added placeless.py for Z3-style setup. Thanks to Whit Morriss.
- Fixed functional.http() to only pass the request body (no headers) to
publish_module(). Thanks to Andreas Zeidler.
- Fixed doctestsuite factory to copy layers from test_class to the suite.
Thanks to Whit Morris.
0.9.8 (Zope 2.8 edition)
- Renamed 'doctest' package to 'zopedoctest' because of name-shadowing
......
......@@ -27,12 +27,16 @@ if __name__ == '__main__':
import unittest
TestRunner = unittest.TextTestRunner
suite = unittest.TestSuite()
cwd = os.getcwd()
def test_finder(recurse, dir, names):
if dir == os.curdir or '__init__.py' in names:
parts = [x for x in dir[len(os.curdir):].split(os.sep) if x]
tests = [x for x in names if x.startswith('test') and x.endswith('.py')]
for test in tests:
if test == 'tests.py' and 'ZopeTestCase' in cwd:
# Skip tests.py when running ZTC tests
continue
modpath = parts + [test[:-3]]
m = __import__('.'.join(modpath))
for part in modpath[1:]:
......
##############################################################################
#
# Copyright (c) 2006 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.
#
##############################################################################
"""Test runner that works with zope.testing.testrunner
$Id$
"""
import unittest
import os
import Testing.ZopeTestCase
suite = unittest.TestSuite()
names = os.listdir(os.path.dirname(__file__))
tests = [x[:-3] for x in names
if x.startswith('test') and x.endswith('.py')
and x != 'tests.py'
# Don't run this module as part of the Zope2 suite
and x != 'testWebserver.py']
for test in tests:
m = __import__('Testing.ZopeTestCase.%s' % test)
m = getattr(Testing.ZopeTestCase, test)
if hasattr(m, 'test_suite'):
suite.addTest(m.test_suite())
def test_suite():
return suite
......@@ -204,15 +204,22 @@ class ZopeSuiteFactory:
def __init__(self, *args, **kw):
self._args = args
self._kw = kw
self._layer = None
self.setup_globs()
self.setup_test_class()
self.setup_optionflags()
def doctestsuite(self):
return doctest.DocTestSuite(*self._args, **self._kw)
suite = doctest.DocTestSuite(*self._args, **self._kw)
if self._layer is not None:
suite.layer = self._layer
return suite
def docfilesuite(self):
return doctest.DocFileSuite(*self._args, **self._kw)
suite = doctest.DocFileSuite(*self._args, **self._kw)
if self._layer is not None:
suite.layer = self._layer
return suite
def setup_globs(self):
globs = self._kw.setdefault('globs', {})
......@@ -228,6 +235,10 @@ class ZopeSuiteFactory:
if 'test_class' in self._kw:
del self._kw['test_class']
# Fix for http://zope.org/Collectors/Zope/2178
if hasattr(test_class, 'layer'):
self._layer = test_class.layer
# If the test_class does not have a runTest method, we add
# a dummy attribute so that TestCase construction works.
if not hasattr(test_class, 'runTest'):
......@@ -307,18 +318,15 @@ def ZopeDocTestSuite(module=None, **kw):
module = doctest._normalize_module(module)
return ZopeSuiteFactory(module, **kw).doctestsuite()
def ZopeDocFileSuite(*paths, **kw):
if kw.get('module_relative', True):
kw['package'] = doctest._normalize_module(kw.get('package'))
return ZopeSuiteFactory(*paths, **kw).docfilesuite()
def FunctionalDocTestSuite(module=None, **kw):
module = doctest._normalize_module(module)
return FunctionalSuiteFactory(module, **kw).doctestsuite()
def FunctionalDocFileSuite(*paths, **kw):
if kw.get('module_relative', True):
kw['package'] = doctest._normalize_module(kw.get('package'))
......
If the layer is extracted properly, we should see the following
variable
>>> getattr(self.app, 'LAYER_EXTRACTED', False)
True
......@@ -27,12 +27,16 @@ if __name__ == '__main__':
import unittest
TestRunner = unittest.TextTestRunner
suite = unittest.TestSuite()
cwd = os.getcwd()
def test_finder(recurse, dir, names):
if dir == os.curdir or '__init__.py' in names:
parts = [x for x in dir[len(os.curdir):].split(os.sep) if x]
tests = [x for x in names if x.startswith('test') and x.endswith('.py')]
for test in tests:
if test == 'tests.py' and 'ZopeTestCase' in cwd:
# Skip tests.py when running ZTC tests
continue
modpath = parts + [test[:-3]]
m = __import__('.'.join(modpath))
for part in modpath[1:]:
......
##############################################################################
#
# Copyright (c) 2006 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.
#
##############################################################################
"""Test layer extraction feature
$Id$
"""
from unittest import TestSuite
from Testing import ZopeTestCase
from Testing.ZopeTestCase import ZopeDocFileSuite
from Testing.ZopeTestCase import ZopeDocTestSuite
from Testing.ZopeTestCase import transaction
class TestLayer:
"""
If the layer is extracted properly, we should see the following
variable
>>> getattr(self.app, 'LAYER_EXTRACTED', False)
True
"""
@classmethod
def setUp(cls):
app = ZopeTestCase.app()
app.LAYER_EXTRACTED = True
transaction.commit()
ZopeTestCase.close(app)
@classmethod
def tearDown(cls):
app = ZopeTestCase.app()
delattr(app, 'LAYER_EXTRACTED')
transaction.commit()
ZopeTestCase.close(app)
class TestCase(ZopeTestCase.ZopeTestCase):
layer = TestLayer
def test_suite():
return TestSuite((
ZopeDocTestSuite(test_class=TestCase),
ZopeDocFileSuite('layerextraction.txt', test_class=TestCase),
))
##############################################################################
#
# Copyright (c) 2006 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.
#
##############################################################################
"""Test runner that works with zope.testing.testrunner
$Id$
"""
import unittest
import os
import Testing.ZopeTestCase.zopedoctest
suite = unittest.TestSuite()
names = os.listdir(os.path.dirname(__file__))
tests = [x[:-3] for x in names
if x.startswith('test') and x.endswith('.py')
and x != 'tests.py']
for test in tests:
m = __import__('Testing.ZopeTestCase.zopedoctest.%s' % test)
m = getattr(Testing.ZopeTestCase.zopedoctest, test)
if hasattr(m, 'test_suite'):
suite.addTest(m.test_suite())
def test_suite():
return suite
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