[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/app/tests/test.py Allow multiple modfilter and testfilter expressions.

Fred L. Drake, Jr. fred at zope.com
Thu Jul 1 14:58:20 EDT 2004


Log message for revision 26020:
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.



-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/tests/test.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/tests/test.py	2004-07-01 18:13:05 UTC (rev 26019)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/tests/test.py	2004-07-01 18:58:20 UTC (rev 26020)
@@ -13,7 +13,7 @@
 #
 ##############################################################################
 """
-test.py [-abBcdDfFgGhklLmMPprstTuUv] [modfilter [testfilter]]
+test.py [-abBcdDfFgGhklLmMPprstTuUv] [modfilter [testfilter...]]
 
 Find and run tests written using the unittest module.
 
@@ -200,7 +200,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
@@ -209,10 +209,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:
 
@@ -489,13 +493,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):
@@ -853,8 +861,8 @@
     if argv is None:
         argv = sys.argv
 
-    MODULE_FILTER = None
-    TEST_FILTER = None
+    MODULE_FILTERS = []
+    TEST_FILTERS = []
     VERBOSE = 0
     LOOP = False
     GUI = False
@@ -895,6 +903,7 @@
                                     "pychecker", "debug", "pdebug",
                                     "gc-threshold=", "gc-option=",
                                     "loop", "gui", "minimal-gui",
+                                    "method=", "module=",
                                     "profile", "progress", "refcount", "trace",
                                     "top-fifty", "verbose",
                                     ])
@@ -977,6 +986,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
@@ -1073,8 +1086,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
@@ -1086,7 +1099,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()
@@ -1098,7 +1111,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:



More information about the Zope3-Checkins mailing list