[Checkins] SVN: Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/
Add support for easy layer setup.
Uli Fouquet
uli at gnufix.de
Sun Feb 3 08:47:06 EST 2008
Log message for revision 83450:
Add support for easy layer setup.
Changed:
U Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/__init__.py
U Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/base.py
U Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/doctesting.py
U Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/testrunner.txt
-=-
Modified: Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/__init__.py
===================================================================
--- Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/__init__.py 2008-02-03 12:29:55 UTC (rev 83449)
+++ Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/__init__.py 2008-02-03 13:47:05 UTC (rev 83450)
@@ -6,11 +6,11 @@
from z3c.testsetup.util import get_package
import unittest
-def register_all_tests(pkg_or_dotted_name):
+def register_all_tests(pkg_or_dotted_name, *args, **kwargs):
pkg = get_package(pkg_or_dotted_name)
def tempfunc():
suite = unittest.TestSuite()
- suite.addTest(collect_pytests(pkg))
- suite.addTest(collect_doctests(pkg))
+ suite.addTest(collect_pytests(pkg, *args, **kwargs))
+ suite.addTest(collect_doctests(pkg, *args, **kwargs))
return suite
return tempfunc
Modified: Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/base.py
===================================================================
--- Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/base.py 2008-02-03 12:29:55 UTC (rev 83449)
+++ Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/base.py 2008-02-03 13:47:05 UTC (rev 83450)
@@ -34,13 +34,23 @@
additional_options = {}
- def __init__(self, package, filter_func=None, extensions=None, **kw):
+ def __init__(self, package, filter_func=None, extensions=None,
+ zcml_config = None, layer_name=None, **kw):
self.package = get_package(package)
self.filter_func = filter_func or self.isTestFile
self.extensions = extensions or self.extensions
+ self.layer_name = layer_name
+ self.zcml_config = zcml_config
self.additional_options = kw
+ self._init(package, filter_func, extensions, zcml_config, **kw)
return
+ def _init(self, package, *args, **kw):
+ """Derived classes can overwrite this method for specialized
+ setups.
+ """
+ pass
+
def setUp(self, test):
pass
Modified: Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/doctesting.py
===================================================================
--- Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/doctesting.py 2008-02-03 12:29:55 UTC (rev 83449)
+++ Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/doctesting.py 2008-02-03 13:47:05 UTC (rev 83450)
@@ -101,6 +101,22 @@
'^\s*:(T|t)est-(L|l)ayer:\s*(functional)\s*',
]
+ def _init(self, package, *args, **kwargs):
+ """Setup a special ZCML layer if requested.
+ """
+ if self.zcml_config is not None:
+ zcml_file = self.zcml_config
+ if not os.path.isfile(zcml_file):
+ zcml_file = os.path.join(
+ os.path.dirname(self.package.__file__),
+ zcml_file)
+ layer_name = 'FunctionalLayer'
+ if self.layer_name is not None:
+ layer_name = self.layer_name
+ self.layer = ZCMLLayer(zcml_file, self.package.__name__,
+ layer_name)
+ return
+
def setUp(self, test):
FunctionalTestSetup().setUp()
@@ -133,14 +149,13 @@
def collect_doctests(package, *args, **kwargs):
suite = unittest.TestSuite()
- test = UnitDocTestSetup(package).getTestSuite()
suite.addTests(
- UnitDocTestSetup(package).getTestSuite())
+ UnitDocTestSetup(package, *args, **kwargs).getTestSuite())
suite.addTest(
- FunctionalDocTestSetup(package).getTestSuite())
+ FunctionalDocTestSetup(package, *args, **kwargs).getTestSuite())
return suite
-def register_doctests(pkg_or_dotted_name):
+def register_doctests(pkg_or_dotted_name, *args, **kwargs):
"""Return a function that requires no argument and delivers a test
suite.
@@ -154,6 +169,6 @@
"""
pkg = get_package(pkg_or_dotted_name)
def tmpfunc():
- return collect_doctests(pkg)
+ return collect_doctests(pkg, *args, **kwargs)
return tmpfunc
Modified: Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/testrunner.txt
===================================================================
--- Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/testrunner.txt 2008-02-03 12:29:55 UTC (rev 83449)
+++ Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/testrunner.txt 2008-02-03 13:47:05 UTC (rev 83450)
@@ -59,7 +59,6 @@
package, whose name we passed in dotted name notation as a
string. This is enough information for a testrunner::
- >>> import sys
>>> defaults = [
... '--path', cavepath,
... '--tests-pattern', '^samplesetup_short1$',
@@ -92,7 +91,6 @@
Here we register all doctests from the ``cave`` module. Let's start a
testrunner with this setup::
- >>> import sys
>>> defaults = [
... '--path', cavepath,
... '--tests-pattern', '^samplesetup_short2$',
@@ -127,7 +125,6 @@
time we pass the `-vv` option to the testrunner, to get some more
information from the run::
- >>> import sys
>>> defaults = [
... '--path', cavepath,
... '--tests-pattern', '^samplesetup_short3$',
@@ -143,6 +140,58 @@
False
+Modified short setups
+---------------------
+
+The default settings of test setups might serve for plain testing
+environments. Especially for functional tests, however, one often want
+to set some basic values not foreseeable by default. Here some hints,
+how default settings can be tweaked.
+
+Setting ZCML config file for functional tests
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Functional tests often require ZCML registration of components to make
+sense. For example one wants to register permissions etc. for use with
+a testbrowser. In other words: often one wants to register a custom
+ZCML layer when running functional doctests. This can be archieved as
+follows:
+
+We wrote a (more or less empty) ZCML config file in the ``cave``
+package, which we want to be registered with functional doctests. To
+do that, we use the now well-known ``register_all_tests`` function,
+but give a ZCML file path and a layer name as arguments::
+
+ >>> setupfile = os.path.join(cavepath, 'samplesetup_short4.py')
+ >>> print open(setupfile).read()
+ import z3c.testsetup
+ test_suite = z3c.testsetup.register_all_tests(
+ 'z3c.testsetup.tests.cave',
+ zcml_config='sampleftesting.zcml',
+ layer_name = 'SampleLayer')
+
+This will result in::
+
+ >>> defaults = [
+ ... '--path', cavepath,
+ ... '--tests-pattern', '^samplesetup_short4$',
+ ... ]
+ >>> sys.argv = 'test '.split()
+ >>> from zope.testing import testrunner
+ >>> testrunner.run(defaults)
+ Running unit tests:
+ Ran 2 tests with 0 failures and 0 errors in 0.001 seconds.
+ Running z3c.testsetup.tests.cave.SampleLayer tests:
+ Set up z3c.testsetup.tests.cave.SampleLayer in 0.005 seconds.
+ Ran 2 tests with 0 failures and 0 errors in 0.001 seconds.
+ Tearing down left over layers:
+ Tear down z3c.testsetup.tests.cave.SampleLayer ... not supported
+ Total: 4 tests, 0 failures, 0 errors in 0.055 seconds.
+ False
+
+Apparently now the custom ZCML file in the ``cave`` package was used.
+
+
Extended setups
---------------
@@ -173,7 +222,6 @@
configured such, that all files named 'samplesetup1.py' will be asked
to return a testsuite::
- >>> import sys
>>> defaults = [
... '--path', cavepath,
... '--tests-pattern', '^samplesetup1$',
More information about the Checkins
mailing list