[Checkins] SVN: Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/testing.py Support for pfilter_func keyword.

Uli Fouquet uli at gnufix.de
Tue Feb 5 09:42:48 EST 2008


Log message for revision 83534:
  Support for pfilter_func keyword.

Changed:
  U   Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/testing.py

-=-
Modified: Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/testing.py
===================================================================
--- Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/testing.py	2008-02-05 14:42:25 UTC (rev 83533)
+++ Sandbox/ulif/z3c-testsetup/trunk/src/z3c/testsetup/testing.py	2008-02-05 14:42:47 UTC (rev 83534)
@@ -23,6 +23,7 @@
 from martian.scan import module_info_from_dotted_name
 from z3c.testsetup.base import BasicTestSetup
 from z3c.testsetup.util import get_package
+from z3c.testsetup.doctesting import _collect_tests
 
 class UnitTestSetup(BasicTestSetup):
     """A unit test setup for packages.
@@ -44,6 +45,10 @@
         '^\s*:(T|t)est-(L|l)ayer:\s*(python)\s*',
         ]
 
+    def __init__(self, package, filter_func=None):
+        BasicTestSetup.__init__(self, package)
+        self.filter_func = filter_func or self.isTestModule
+
     def docstrContains(self, docstr, regexp_list):
         """Does a docstring contain lines matching every of the regular
         expressions?
@@ -82,7 +87,7 @@
                 result.extend(self.getModules(submod_info.getModule()))
             else:
                 module = submod_info.getModule()
-                if self.isTestModule(module):
+                if self.filter_func(module):
                     result.append(module)
         return result
         
@@ -95,15 +100,15 @@
             suite.addTest(tests)
         return suite
 
-
 def get_pytests_suite(pkg_or_dotted_name, *args, **kwargs):
-    pkg = get_package(pkg_or_dotted_name)
-    suite = unittest.TestSuite()
-    suite.addTest(
-        UnitTestSetup(pkg).getTestSuite())
-    return suite
-    
+    kws = ['pfilter_func',]
+    options = kwargs.copy()
+    if 'filter_func' in kwargs.keys():
+        del(options['filter_func'])
+    return _collect_tests(pkg_or_dotted_name, UnitTestSetup,
+                          typespec_kws=kws, *args, **options)
 
+
 def register_pytests(pkg_or_dotted_name, *args, **kwargs):
     """Return a function that requires no argument and delivers a test
     suite.
@@ -118,6 +123,6 @@
     """
     pkg = get_package(pkg_or_dotted_name)
     def tmpfunc():
-        return get_pytests_suite(pkg)
+        return get_pytests_suite(pkg, *args, **kwargs)
     return tmpfunc
     



More information about the Checkins mailing list