aboutsummaryrefslogtreecommitdiffstats
path: root/test.py
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2010-01-27 08:39:00 -0500
committerW. Trevor King <wking@drexel.edu>2010-01-27 08:39:00 -0500
commit8a07fe257946104c80f656617c168a340f4dae77 (patch)
tree6f96bfe7554bb90bd1743a9284e1cb2f5742b09c /test.py
parentd2752cde56e7cf67abc2e7f0a0fc91612016585f (diff)
downloadbugseverywhere-8a07fe257946104c80f656617c168a340f4dae77.tar.gz
Add --help, --quiet options to test.py.
Fixes Ben's "unintuitive test.py interface" bug: Date: Wed, 27 Jan 2010 14:09:14 +1100 From: Ben Finney Subject: [Be-devel] Re: Test suite on Trevor's development branch ... > $ python ./test.py -q > > ---------------------------------------------------------------------- > Ran 0 tests in 0.000s > > OK Running a Python unittest-capable test suite with "-q" should run it in "quiet" mode, where progress is indicated by single characters along a lone, and only failures and errors are reported. ...
Diffstat (limited to 'test.py')
-rw-r--r--test.py76
1 files changed, 43 insertions, 33 deletions
diff --git a/test.py b/test.py
index fc7e5d3..5f00ac1 100644
--- a/test.py
+++ b/test.py
@@ -16,17 +16,6 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-"""Usage: python test.py [module(s) ...]
-
-When called without optional module names, run the test suites for
-*all* modules. This may raise lots of errors if you haven't installed
-one of the versioning control systems.
-
-When called with module name arguments, only run the test suites from
-those modules and their submodules. For example:
- python test.py libbe.bugdir libbe.storage
-"""
-
import doctest
import os
import os.path
@@ -84,27 +73,48 @@ def add_module_tests(suite, modname):
pass
suite.addTest(s)
-suite = unittest.TestSuite()
-tree = python_tree()
-if len(sys.argv) <= 1:
- for node in tree.traverse():
- add_module_tests(suite, node.modname)
-else:
- added = []
- for modname in sys.argv[1:]:
- for node in tree.traverse():
- if node.modname == modname:
- for n in node.traverse():
- if n.modname not in added:
- add_module_tests(suite, n.modname)
- added.append(n.modname)
- break
+if __name__ == '__main__':
+ import optparse
+ parser = optparse.OptionParser(usage='%prog [options] [modules ...]',
+ description=
+"""When called without optional module names, run the test suites for
+*all* modules. This may raise lots of errors if you haven't installed
+one of the versioning control systems.
+
+When called with module name arguments, only run the test suites from
+those modules and their submodules. For example::
-result = unittest.TextTestRunner(verbosity=2).run(suite)
+ $ python test.py libbe.bugdir libbe.storage
+""")
+ parser.add_option('-q', '--quiet', action='store_true', default=False,
+ help='Run unittests in quiet mode (verbosity 1).')
+ options,args = parser.parse_args()
-numErrors = len(result.errors)
-numFailures = len(result.failures)
-numBad = numErrors + numFailures
-if numBad > 126:
- numBad = 1
-sys.exit(numBad)
+ verbosity = 2
+ if options.quiet == True:
+ verbosity = 1
+
+ suite = unittest.TestSuite()
+ tree = python_tree()
+ if len(args) == 0:
+ for node in tree.traverse():
+ add_module_tests(suite, node.modname)
+ else:
+ added = []
+ for modname in args:
+ for node in tree.traverse():
+ if node.modname == modname:
+ for n in node.traverse():
+ if n.modname not in added:
+ add_module_tests(suite, n.modname)
+ added.append(n.modname)
+ break
+
+ result = unittest.TextTestRunner(verbosity=verbosity).run(suite)
+
+ numErrors = len(result.errors)
+ numFailures = len(result.failures)
+ numBad = numErrors + numFailures
+ if numBad > 126:
+ numBad = 1
+ sys.exit(numBad)