From: W. Trevor King Date: Wed, 27 Jan 2010 13:39:00 +0000 (-0500) Subject: Add --help, --quiet options to test.py. X-Git-Tag: 1.0.0~59^2~35^2~1 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8a07fe257946104c80f656617c168a340f4dae77;p=be.git 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. ... --- 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)