[Zodb-checkins] CVS: StandaloneZODB - test.py:1.2

Jeremy Hylton jeremy@zope.com
Wed, 8 Aug 2001 13:36:17 -0400


Update of /cvs-repository/StandaloneZODB
In directory cvs.zope.org:/tmp/cvs-serv27325

Modified Files:
	test.py 
Log Message:
A few enhancements to the script

command-line arguments:

-v : verbose
arg: exclude any tests that don't contain this regex


=== StandaloneZODB/test.py 1.1 => 1.2 ===
+import re
 import sys
 import unittest
 from distutils.util import get_platform
 
 # setup list of directories to put on the path
 
-PLAT_SPEC = "%s-%s" % (get_platform(), sys.version[0:3])
-DIRS = ["lib",
-        "lib.%s" % PLAT_SPEC,
-        "../ExtensionClass/build/lib.%s" % PLAT_SPEC,
-        ]
-for d in DIRS:
-    sys.path.insert(0, d)
+def setup_path():
+    PLAT_SPEC = "%s-%s" % (get_platform(), sys.version[0:3])
+    DIRS = ["lib",
+            "lib.%s" % PLAT_SPEC,
+            "../ExtensionClass/build/lib.%s" % PLAT_SPEC,
+            ]
+    for d in DIRS:
+        sys.path.insert(0, d)
 
 # find test files
 class TestFileFinder:
     def __init__(self):
         self.files = []
 
-    def visit(self, arg, dir, files):
+    def visit(self, rx, dir, files):
         if dir.startswith("./build"):
             return
         if not dir.endswith("tests"):
@@ -29,10 +31,17 @@
         for file in files:
             if file.startswith("test") and file.endswith(".py"):
                 path = os.path.join(dir, file)
-                self.files.append(path)
-
-finder = TestFileFinder()
-os.path.walk(".", finder.visit, None)
+                if rx is not None:
+                    if rx.search(path):
+                        self.files.append(path)
+                else:
+                    self.files.append(path)
+
+def find_tests(filter):
+    rx = re.compile(filter)
+    finder = TestFileFinder()
+    os.path.walk(".", finder.visit, rx)
+    return finder.files
 
 def package_import(modname):
     mod = __import__(modname)
@@ -40,21 +49,39 @@
         mod = getattr(mod, part)
     return mod
 
-os.chdir("build")
-
-alltests = unittest.TestSuite()
-
-runner = unittest.TextTestRunner()
-for file in finder.files:
-    assert file.startswith('./')
-    assert file.endswith('.py')
-    modname = file[2:-3]
-    modname = modname.replace(os.sep, '.')
-    mod = package_import(modname)
-    try:
-        suite = mod.test_suite()
-    except AttributeError:
-        continue
-    print modname
-    runner.run(suite)
-
+def main(filter=None):
+    setup_path()
+    files = find_tests(filter)
+
+    os.chdir("build")
+
+    alltests = unittest.TestSuite()
+
+    runner = unittest.TextTestRunner(verbosity=VERBOSE)
+    for file in files:
+        assert file.startswith('./')
+        assert file.endswith('.py')
+        modname = file[2:-3]
+        modname = modname.replace(os.sep, '.')
+        mod = package_import(modname)
+        try:
+            suite = mod.test_suite()
+        except AttributeError:
+            continue
+        print modname, len(suite._tests)
+        runner.run(suite)
+
+
+if __name__ == "__main__":
+    import getopt
+
+    filter = None
+    VERBOSE = 0
+
+    opts, args = getopt.getopt(sys.argv[1:], 'v')
+    for k, v in opts:
+        if k == '-v':
+            VERBOSE += 1
+    if args:
+        filter = args[0]
+    main(filter)