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

Jeremy Hylton jeremy@zope.com
Fri, 22 Nov 2002 16:14:53 -0500


Update of /cvs-repository/ZODB4
In directory cvs.zope.org:/tmp/cvs-serv6057

Modified Files:
	test.py 
Log Message:
Merge new options from Zope3 version of test.py.

-D, -G, -u, -m, -C


=== ZODB4/test.py 1.1 => 1.2 ===
--- ZODB4/test.py:1.1	Tue Jun 25 13:29:23 2002
+++ ZODB4/test.py	Fri Nov 22 16:14:53 2002
@@ -27,6 +27,9 @@
     Unfortunately, the debug harness doesn't print the name of the
     test, so Use With Care.
 
+-D  debugger
+    Works like -d, except that it loads pdb when an exception occurs.
+
 -v  verbose
     With one -v, unittest prints a dot (".") for each test run.  With
     -vv, unittest prints the name of each test (for some definition of
@@ -43,6 +46,19 @@
     the threshold is set to 1 (agressive garbage collection).  Do "-g 0" to
     disable garbage collection altogether.
 
+-G flag
+    Set garbage collector debug flag.  The flag argument should be the name
+    of a DEBUG_ attribute of the gc module.  This argument can be repeated.
+
+-u  Use unittestgui
+-m  Use unittestgui; start minimized
+    Use the PyUnit GUI instead of output to the command line. The GUI
+    imports tests on its own, taking care to reload all dependencies on each
+    run. The debug (-d), verbose (-v), and Loop (-L) options will be
+    ignored. The testfilter filter is also not applied.
+
+-C  use pychecker
+
 modfilter
 testfilter
     Case-sensitive regexps to limit which tests are run, used in search
@@ -71,9 +87,17 @@
     As before, but runs all tests whose names aren't precisely
     "checkWriteClient".  Useful to avoid a specific failing test you don't
     want to deal with just yet.
+
+    test.py -m . "!^checkWriteClient$"
+
+    As before, but now opens up a minimized PyUnit GUI window (only showing
+    the progressbar). Double-clicking the progressbar will start the import
+    and run all tests. Useful for refactoring runs where you continually
+    want to make sure all tests still pass.
 """
 
 import os
+import pdb
 import re
 import sys
 import traceback
@@ -230,16 +254,34 @@
                 new.addTest(filtered)
     return new
 
+def gui_runner(files, test_filter):
+    sys.path.insert(0, join(os.getcwd(), 'utilities'))
+    import unittestgui
+    suites = []
+    for file in files:
+        suites.append(module_from_path(file) + '.test_suite')
+
+    suites = ", ".join(suites)
+    minimal = (GUI == 'minimal')
+    unittestgui.main(suites, minimal)
+
 def runner(files, test_filter, debug):
     runner = ImmediateTestRunner(verbosity=VERBOSE, debug=debug)
     suite = unittest.TestSuite()
     for file in files:
         s = get_suite(file)
-        if s is not None:
-            if test_filter is not None:
-                s = filter_testcases(s, test_filter)
-            suite.addTest(s)
-    r = runner.run(suite)
+        if s is None:
+            continue
+        if test_filter is not None:
+            s = filter_testcases(s, test_filter)
+        suite.addTest(s)
+    try:
+        r = runner.run(suite)
+    except:
+        if debugger:
+            pdb.post_mortem(sys.exc_info()[2])
+        else:
+            raise
 
 def remove_stale_bytecode(arg, dirname, names):
     names = map(os.path.normcase, names)
@@ -257,20 +299,27 @@
     files = find_tests(module_filter)
     files.sort()
 
-    if LOOP:
+    if GUI:
+        gui_runner(files, test_filter)
+    elif LOOP:
         while 1:
             runner(files, test_filter, debug)
     else:
         runner(files, test_filter, debug)
 
 
-def process_args():
+def process_args(argv=None):
+    if argv is None:
+        argv = sys.argv
+        
     import getopt
     global module_filter
     global test_filter
     global VERBOSE
     global LOOP
+    global GUI
     global debug
+    global debugger
     global build
     global gcthresh
 
@@ -278,16 +327,18 @@
     test_filter = None
     VERBOSE = 0
     LOOP = 0
+    GUI = 0
     debug = 0 # Don't collect test results; simply let tests crash
+    debugger = 0
     build = 0
     gcthresh = None
+    gcflags = []
 
     try:
-        opts, args = getopt.getopt(sys.argv[1:], 'vdLbhCg:',
-                                   ['help'])
+        opts, args = getopt.getopt(argv[1:], 'vdDLbhCumg:G:', ['help'])
     except getopt.error, msg:
         print msg
-        print "Try `python %s -h' for more information." % sys.argv[0]
+        print "Try `python %s -h' for more information." % argv[0]
         sys.exit(2)
 
     for k, v in opts:
@@ -295,6 +346,9 @@
             VERBOSE += 1
         elif k == '-d':
             debug = 1
+        elif k == '-D':
+            debug = 1
+            debugger = 1
         elif k == '-L':
             LOOP = 1
         elif k == '-b':
@@ -303,14 +357,36 @@
             print __doc__
             sys.exit(0)
         elif k == '-C':
+            os.environ['PYCHECKER'] = "-e -q"
             import pychecker.checker
         elif k == '-g':
             gcthresh = int(v)
+        elif k == '-u':
+            GUI = 1
+        elif k == '-m':
+            GUI = 'minimal'
+        elif k == '-G':
+            if not v.startswith("DEBUG_"):
+                print "-G argument must be DEBUG_ flag, not", repr(v)
+                sys.exit(1)
+            gcflags.append(v)
 
     if gcthresh is not None:
         import gc
         gc.set_threshold(gcthresh)
         print 'gc threshold:', gc.get_threshold()
+
+    if gcflags:
+        import gc
+        val = 0
+        for flag in gcflags:
+            v = getattr(gc, flag, None)
+            if v is None:
+                print "Unknown gc flag", repr(flag)
+                print gc.set_debug.__doc__
+                sys.exit(1)
+            val |= v
+        gc.set_debug(v)
 
     if build:
         cmd = sys.executable + " build.py"