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

Nuked the decorator and moved its functionality to the suite factory proper.

Fixes http://www.zope.org/Collectors/Zope/2178
parent 71a575ad
......@@ -195,30 +195,27 @@ def http(request_string, handle_errors=True):
return DocResponseWrapper(response, outstream, path, header_output)
def extractLayer(func):
def wrap(*args, **kw):
suite = func(*args, **kw)
tc = kw.get('test_class', None)
if tc and hasattr(tc, 'layer'):
suite.layer = tc.layer
return suite
return wrap
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', {})
......@@ -234,6 +231,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'):
......@@ -309,26 +310,22 @@ class FunctionalSuiteFactory(ZopeSuiteFactory):
| doctest.NORMALIZE_WHITESPACE)
@extractLayer
def ZopeDocTestSuite(module=None, **kw):
module = doctest._normalize_module(module, depth=3)
module = doctest._normalize_module(module)
return ZopeSuiteFactory(module, **kw).doctestsuite()
@extractLayer
def ZopeDocFileSuite(*paths, **kw):
if kw.get('module_relative', True):
kw['package'] = doctest._normalize_module(kw.get('package'), depth=3)
kw['package'] = doctest._normalize_module(kw.get('package'))
return ZopeSuiteFactory(*paths, **kw).docfilesuite()
@extractLayer
def FunctionalDocTestSuite(module=None, **kw):
module = doctest._normalize_module(module, depth=3)
module = doctest._normalize_module(module)
return FunctionalSuiteFactory(module, **kw).doctestsuite()
@extractLayer
def FunctionalDocFileSuite(*paths, **kw):
if kw.get('module_relative', True):
kw['package'] = doctest._normalize_module(kw.get('package'), depth=3)
kw['package'] = doctest._normalize_module(kw.get('package'))
return FunctionalSuiteFactory(*paths, **kw).docfilesuite()
......
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