Mercurial > hgsubversion
diff tests/run.py @ 610:300b917d23c5
testrunner: use optparse
author | Dan Villiom Podlaski Christiansen <danchr@gmail.com> |
---|---|
date | Fri, 14 May 2010 17:39:26 +0200 |
parents | 930bb6df19a0 |
children | 58f397523604 |
line wrap: on
line diff
--- a/tests/run.py +++ b/tests/run.py @@ -1,3 +1,4 @@ +import optparse import os import sys import unittest @@ -36,11 +37,23 @@ def comprehensive(mod): return dir == 'comprehensive' if __name__ == '__main__': + description = ("This script runs the hgsubversion tests. If no tests are " + "specified, all known tests are implied.") + parser = optparse.OptionParser(usage="%prog [options] [TESTS ...]", + description=description) + parser.add_option("-A", "--all", + dest="comprehensive", action="store_true", default=False, + help="include slow, but comprehensive tests") + parser.add_option("-v", "--verbose", + dest="verbose", action="store_true", default=False, + help="enable verbose output") - kwargs = {'descriptions': 2} - if '-v' in sys.argv: - kwargs['descriptions'] = 3 - kwargs['verbosity'] = 2 + (options, args) = parser.parse_args() + + if options.verbose: + testargs = { 'descriptions': 3, 'verbosity': 2 } + else: + testargs = {'descriptions': 2} # silence output when running outside nose sys.stdout = os.tmpfile() @@ -49,22 +62,23 @@ if __name__ == '__main__': all = dict((k, v) for (k, v) in all.iteritems() if k.startswith('test_')) del all['test_util'] - args = [i for i in sys.argv[1:] if i.startswith('test')] args = [i.split('.py')[0].replace('-', '_') for i in args] if not args: - check = lambda x: '-A' in sys.argv or not comprehensive(x) + check = lambda x: options.comprehensive or not comprehensive(x) mods = [m for (n, m) in sorted(all.iteritems()) if check(m)] suite = [m.suite() for m in mods] else: suite = [] for arg in args: - if arg not in all: + if arg == 'test_util': + continue + elif arg not in all: print >> sys.stderr, 'test module %s not available' % arg else: suite.append(all[arg].suite()) - runner = unittest.TextTestRunner(**kwargs) + runner = unittest.TextTestRunner(**testargs) result = runner.run(unittest.TestSuite(suite)) if not result.wasSuccessful(): sys.exit(1)