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

Jeremy Hylton jeremy@zope.com
Mon, 30 Dec 2002 12:03:26 -0500


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

Modified Files:
	test.py 
Log Message:
Copy from Zope3.

XXX Maybe this should just become a repolink.


=== ZODB4/test.py 1.12 => 1.13 === (701/801 lines abridged)
--- ZODB4/test.py:1.12	Thu Dec 19 17:50:13 2002
+++ ZODB4/test.py	Mon Dec 30 12:03:26 2002
@@ -2,77 +2,94 @@
 #
 # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
 # All Rights Reserved.
-# 
+#
 # This software is subject to the provisions of the Zope Public License,
 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
-# 
+#
 ##############################################################################
-"""
-test.py [-bdvvL] [modfilter [testfilter]]
+"""Run the test suite.
 
-Test harness.
+Usage: %(PROGRAM)s [options] [modfilter [testfilter]]
+Options:
 
--b  build
-    Run "python setup.py -q build" before running tests, where "python"
-    is the version of python used to run test.py.  Highly recommended.
-
--d  debug
-    Instead of the normal test harness, run a debug version which
-    doesn't catch any exceptions.  This is occasionally handy when the
-    unittest code catching the exception doesn't work right.
-    Unfortunately, the debug harness doesn't print the name of the
-    test, so Use With Care.
+-b
+    Run "python setup.py build" before running tests, where "python" is the
+    version of python used to run test.py.  Highly recommended.  Tests will be
+    run from the build directory.  (Note: In Python < 2.3 the -q flag is
+    added to the setup.py command line.)
+
+-B
+    Run "python setup.py build_ext -i" before running tests.  Tests will be
+    run from the source directory.
+
+-c
+    Use pychecker.
+
+-d
+    Instead of the normal test harness, run a debug version which doesn't

[-=- -=- -=- 701 lines omitted -=- -=- -=-]

+    except ImportError, err:
+        print err
+        print sys.path
+        raise
+
+
+def print_tb_last():
+    tb = sys.exc_info()[2]
+    file = sys.stderr
+    while True:
+        f = tb.tb_frame
+        lineno = traceback.tb_lineno(tb)
+        tb = tb.tb_next
+        if tb is not None:
+            continue
+
+        co = f.f_code
+        filename = co.co_filename
+        name = co.co_name
+        file.write('  File "%s", line %d, in %s\n' % (filename,lineno,name))
+        line = linecache.getline(filename, lineno)
+        if line:
+            file.write('    %s\n' % line.strip())
+        break
+
+
+# The following method is for debugging unit tests from a Python prompt:
+def debug(args=""):
+    """Debug your unit tests with the post mortem debugger.
+
+    Just run the debug function with a string containing command-line
+    arguments. (The function uses a cheesy parser, aka split. ;)
+
+    For example, to debug the tests in package Zope.App.DublinCore:
+
+      import test
+      test.debug('Zope.App.DublinCore')
+
+    At the first failure or error, an exception will be raised. At
+    that point, you can use pdb's post-mortem debugger:
+
+      import pdb
+      pdb.pm()
+    """
+    process_args(["", "-d"] + args.split())
+
 
 if __name__ == "__main__":
     process_args()
-