X-Git-Url: http://git.tremily.us/?a=blobdiff_plain;f=test.py;h=e82b4191e0d8483639f3f3b5f93b87385c9c014d;hb=2b233348db8cfbf19c537679db0dcaaeb958d7b2;hp=f26aaa8a86bbc5c9495d4eec568c2769d4168be7;hpb=80e76f70d58672167b17ddaced6c7856ba703ece;p=be.git diff --git a/test.py b/test.py index f26aaa8..e82b419 100644 --- a/test.py +++ b/test.py @@ -1,15 +1,22 @@ -# Copyright - -"""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 -""" +# Copyright (C) 2005-2012 Aaron Bentley +# Chris Ball +# Marien Zwart +# W. Trevor King +# +# This file is part of Bugs Everywhere. +# +# Bugs Everywhere is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 2 of the License, or (at your option) any +# later version. +# +# Bugs Everywhere is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# Bugs Everywhere. If not, see . import doctest import os @@ -21,6 +28,7 @@ import libbe libbe.TESTING = True from libbe.util.tree import Tree from libbe.util.plugin import import_by_name +from libbe.version import version def python_tree(root_path='libbe', root_modname='libbe'): tree = Tree() @@ -68,27 +76,49 @@ 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() + print >> sys.stderr, 'Testing BE\n%s' % version(verbose=True) -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)