[Zope3-checkins] SVN: Zope3/trunk/ Allow multiple modfilter and testfilter expressions.

Fred L. Drake, Jr. fred at zope.com
Thu Jul 1 15:10:49 EDT 2004


Log message for revision 26025:
Allow multiple modfilter and testfilter expressions.

The --module and --method options allow additional filter expressions to
be specified.  Additional testfilters can also be specified using
positional arguments.

Multiple filters of either type are combined using OR.

Merged from revisions 26020, 26024 on the ZopeX3-3.0 branch.



-=-
Modified: Zope3/trunk/Makefile
===================================================================
--- Zope3/trunk/Makefile	2004-07-01 19:08:01 UTC (rev 26024)
+++ Zope3/trunk/Makefile	2004-07-01 19:10:49 UTC (rev 26025)
@@ -1,5 +1,5 @@
 PYTHON=python2.3
-TESTFLAGS=-p -v
+TESTFLAGS=-v
 TESTOPTS=
 SETUPFLAGS=
 

Modified: Zope3/trunk/src/zope/app/tests/test.py
===================================================================
--- Zope3/trunk/src/zope/app/tests/test.py	2004-07-01 19:08:01 UTC (rev 26024)
+++ Zope3/trunk/src/zope/app/tests/test.py	2004-07-01 19:10:49 UTC (rev 26025)
@@ -13,7 +13,7 @@
 #
 ##############################################################################
 """
-test.py [-abBcdDfFgGhklLmMPprstTuUv] [modfilter [testfilter]]
+test.py [-abBcdDfFgGhklLmMPprstTuUv] [modfilter [testfilter...]]
 
 Find and run tests written using the unittest module.
 
@@ -204,7 +204,7 @@
 
 
 modfilter
-testfilter
+testfilter...
     Case-sensitive regexps to limit which tests are run, used in search
     (not match) mode.
     In an extension of Python regexp notation, a leading "!" is stripped
@@ -213,10 +213,14 @@
     By default these act like ".", i.e. nothing is excluded.
 
     modfilter is applied to a test file's path, starting at "build" and
-    including (OS-dependent) path separators.
+    including (OS-dependent) path separators.  Additional modfilters
+    can be specified with the --module option; modules are matched if
+    they match at least one modfilter.
 
     testfilter is applied to the (method) name of the unittest methods
     contained in the test files whose paths modfilter matched.
+    Additional testfilters can be specified with the --method option;
+    methods are matched if they match at least one testfilter.
 
 Extreme (yet useful) examples:
 
@@ -493,13 +497,17 @@
         else:
             print "Running %s tests from %s" % (kind, self.cwd)
 
-def match(rx, s):
-    if not rx:
+def match(rxlist, s):
+    if not rxlist:
         return True
-    if rx[0] == "!":
-        return re.search(rx[1:], s) is None
-    else:
-        return re.search(rx, s) is not None
+    for rx in rxlist:
+        if rx[0] == "!":
+            matched = re.search(rx[1:], s) is None
+        else:
+            matched = re.search(rx, s) is not None
+        if matched:
+            return True
+    return False
 
 class TestFileFinder:
     def __init__(self, prefix):
@@ -868,8 +876,8 @@
     if argv is None:
         argv = sys.argv
 
-    MODULE_FILTER = None
-    TEST_FILTER = None
+    MODULE_FILTERS = []
+    TEST_FILTERS = []
     VERBOSE = 0
     LOOP = 0
     GUI = False
@@ -911,6 +919,7 @@
                                     "pychecker", "debug", "pdebug",
                                     "gc-threshold=", "gc-option=",
                                     "loop", "gui", "minimal-gui",
+                                    "method=", "module=",
                                     "profile", "progress", "refcount", "trace",
                                     "top-fifty", "verbose", "repeat="
                                     ])
@@ -995,6 +1004,10 @@
                 TIMESFN = v
         elif k in ('-s', '--dir'):
             TEST_DIRS.append(v)
+        elif k == "method":
+            TEST_FILTERS.append(v)
+        elif k == "--module":
+            MODULE_FILTERS.append(v)
 
     if PYCHECKER:
         # make sure you have a recent version of pychecker
@@ -1091,8 +1104,8 @@
 
         if args:
             if len(args) > 1:
-                TEST_FILTER = args[1]
-            MODULE_FILTER = args[0]
+                TEST_FILTERS.extend(args[1:])
+            MODULE_FILTERS.append(args[0])
         try:
             if TRACE:
                 # if the trace module is used, then we don't exit with
@@ -1104,7 +1117,7 @@
                                      ignoremods=ignoremods,
                                      trace=False, count=True)
 
-                tracer.runctx("main(MODULE_FILTER, TEST_FILTER, LIBDIR)",
+                tracer.runctx("main(MODULE_FILTERS, TEST_FILTERS, LIBDIR)",
                               globals=globals(), locals=vars())
                 r = tracer.results()
                 path = "/tmp/trace.%s" % os.getpid()
@@ -1116,7 +1129,7 @@
                 r.write_results(show_missing=True,
                                 summary=True, coverdir=coverdir)
             else:
-                bad = main(MODULE_FILTER, TEST_FILTER, LIBDIR)
+                bad = main(MODULE_FILTERS, TEST_FILTERS, LIBDIR)
                 if bad:
                     sys.exit(1)
         except ImportError, err:

Modified: Zope3/trunk/test.config
===================================================================
--- Zope3/trunk/test.config	2004-07-01 19:08:01 UTC (rev 26024)
+++ Zope3/trunk/test.config	2004-07-01 19:10:49 UTC (rev 26025)
@@ -104,10 +104,10 @@
 # GUI = False
 
 
-# MODULE_FILTER=<str>
-# Regular expression (in string format) for matching test module paths
-# MODULE_FILTER = None
+# MODULE_FILTERS=[<str>, ...]
+# List of regular expressions (in string format) for matching test module paths
+# MODULE_FILTERS = []
 
-# TEST_FILTER=<str>
-# Regular expression (in string format) for matching test names
-# TEST_FILTER = None
+# TEST_FILTERS=[<str>, ...]
+# List of regular expressions (in string format) for matching test names
+# TEST_FILTERS = []



More information about the Zope3-Checkins mailing list