[Checkins]
SVN: Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/testgetter.py
Introduce usable TestCollectors.
Uli Fouquet
uli at gnufix.de
Fri Feb 15 07:49:26 EST 2008
Log message for revision 83850:
Introduce usable TestCollectors.
Changed:
U Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/testgetter.py
-=-
Modified: Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/testgetter.py
===================================================================
--- Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/testgetter.py 2008-02-15 10:37:23 UTC (rev 83849)
+++ Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/testgetter.py 2008-02-15 12:49:26 UTC (rev 83850)
@@ -11,7 +11,13 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""Factories for testcollectors.
+"""TestGetters and TestCollectors.
+
+TestGetters wrap ordinary TestSetups and TestCollectors wrap
+TestGetters. They ease the writing of often used ``test_suite()``
+functions in test setup modules of projects.
+
+See testgetter.txt to learn more about this stuff.
"""
import unittest
from z3c.testsetup.doctesting import UnitDocTestSetup, FunctionalDocTestSetup
@@ -19,7 +25,11 @@
from z3c.testsetup.util import get_package, get_keyword_params
class BasicTestGetter(object):
- """Abstract base.
+ """Abstract base for TestGetters.
+
+ TestGetters are a replacement for the test_suite() functions often
+ defined in test setup modules. They are more elegant, more
+ flexible, reusable and better looking ;-)
"""
defaults = {}
settings = {}
@@ -36,10 +46,16 @@
return
def initialize(self):
- self.filter_keywords()
- return
+ """Convenience method called at end of constructor.
+ Might be usable for derived classes.
+ """
+ pass
+
def __call__(self):
+ """Get a testsuite.
+ """
+ self.filterKeywords()
suite = unittest.TestSuite()
suite.addTest(
self.wrapped_class(
@@ -47,7 +63,11 @@
)
return suite
- def filter_keywords(self):
+ def filterKeywords(self):
+ """Filter keywords passed to the constructor.
+
+ See testgetter.txt for deeper insights.
+ """
new_kws = self.defaults.copy()
new_kws.update(self.settings)
self.settings = new_kws
@@ -63,7 +83,14 @@
self.settings = new_kws
return
+ def getTestSuite(self):
+ """A convenience method.
+ Some people might expect this method to exist.
+ """
+ return self.__call__()
+
+
class FunctionalDocTestGetter(BasicTestGetter):
"""Collect functional doctests.
"""
@@ -85,25 +112,37 @@
wrapped_class = UnitTestSetup
special_char = 'p'
-
-class TestGetter(BasicTestGetter):
- """Handle and pass parameters to different test setup types.
+class BasicTestCollector(BasicTestGetter):
+ """Abstract base of TestCollectors.
- In fact ``TestGetter``s are a replacement for the normally used
- ``test_suite()`` functions in test setup modules. Because in that
- case only callables are expected, we can also use classes.
+ TestCollectors are TestGetters, that can handle several TestGetter
+ types at once.
"""
-
+
+ handled_getters = []
def __call__(self):
"""Return a test suite.
"""
suite = unittest.TestSuite()
- for getter in [FunctionalDocTestGetter, UnitDocTestGetter,
- PythonTestGetter]:
- suite_getter = getter(self.package, **self.settings)
- suite_getter.defaults = getattr(self, 'defaults', {})
- suite.addTest(
- suite_getter()
- )
+ for getter_cls in self.handled_getters:
+ getter = getter_cls(self.package, **self.settings)
+ # Merge our defaults with target defaults...
+ target_defaults = getattr(getter, 'defaults', {})
+ self_defaults = getattr(self, 'defaults', {})
+ getter.defaults = target_defaults.copy()
+ getter.defaults.update(self_defaults)
+ suite.addTest(getter.getTestSuite())
return suite
+
+class DocTestCollector(BasicTestCollector):
+ """A TestCollector that wraps functional doctests and unit doctests.
+ """
+ handled_getters = [FunctionalDocTestGetter, UnitDocTestGetter]
+
+class TestCollector(BasicTestCollector):
+ """A TestCollector that wraps doctests and PythonTests.
+ """
+ handled_getters = [FunctionalDocTestGetter, UnitDocTestGetter,
+ PythonTestGetter]
+
More information about the Checkins
mailing list