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

Jeremy Hylton jeremy@zope.com
Mon, 29 Oct 2001 11:12:26 -0500


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

Modified Files:
	test.py 
Log Message:
Run all tests as single suite by default.

-i option runs each module's test independently.



=== StandaloneZODB/test.py 1.9 => 1.10 ===
         pass
 
+def get_suite(file):
+    assert file[:5] == "build"
+    assert file[-3:] == '.py'
+    modname = module_from_path(file)
+    mod = package_import(modname)
+    try:
+        return mod.test_suite()
+    except AttributeError:
+        return None
+
 def main(filter=None):
     setup_path()
     files = find_tests(filter)
 
-    os.chdir("build")
+    os.chdir("build") 
 
     if LOOP:
         suites = []
         for file in files:
-            assert file[:5] == "build"
-            assert file[-3:] == '.py'
-            modname = module_from_path(file)
-            print modname
-            mod = package_import(modname)
-            try:
-                suite = mod.test_suite()
-            except AttributeError:
+            suite = get_suite(file)
+            if suite is None:
                 continue
-            suites.append((modname, len(suite._tests), suite))
+            suites.append(suite)
         if suites:
             runner = unittest.TextTestRunner(verbosity=VERBOSE)
             while 1:
-                for modname, size, suite in suites:
+                for suite in suites:
                     runner.run(suite)
                 gc.collect()
                 check_mem()
     else:
         runner = unittest.TextTestRunner(verbosity=VERBOSE)
-        for file in files:
-            assert file[:5] == "build"
-            assert file[-3:] == '.py'
-            modname = module_from_path(file)
-            print modname
-            mod = package_import(modname)
-            try:
-                suite = mod.test_suite()
-            except AttributeError:
-                continue
-            print modname, len(suite._tests)
+        if MERGE_SUITES:
+            suite = unittest.TestSuite()
+            for file in files:
+                s = get_suite(file)
+                if s is not None:
+                    suite.addTest(s)
             runner.run(suite)
+        else:
+            for file in files:
+                suite = get_suite(file)
+                if suite is None:
+                    continue
+                runner.run(suite)
 
 if __name__ == "__main__":
     import getopt
@@ -166,13 +171,16 @@
     filter = None
     VERBOSE = 0
     LOOP = 0
+    MERGE_SUITES = 1
 
-    opts, args = getopt.getopt(sys.argv[1:], 'vL')
+    opts, args = getopt.getopt(sys.argv[1:], 'vLi')
     for k, v in opts:
         if k == '-v':
             VERBOSE = VERBOSE + 1
         elif k == '-L':
             LOOP = 1
+        elif k == '-i':
+            MERGE_SUITES = 0
     if args:
         filter = args[0]
     try: