From 90f2154a32b513cdaaca1714c8d05bceb87b4303 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Sat, 7 Dec 2013 15:16:09 -0800 Subject: Better test output -- include totals. --- lib/spack/spack/cmd/test.py | 20 ++------------ lib/spack/spack/test/__init__.py | 59 +++++++++++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 24 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/cmd/test.py b/lib/spack/spack/cmd/test.py index b1c8df4eb3..786f6beade 100644 --- a/lib/spack/spack/cmd/test.py +++ b/lib/spack/spack/cmd/test.py @@ -9,7 +9,7 @@ description ="Run unit tests" def setup_parser(subparser): subparser.add_argument( - 'names', nargs='*', help="Names of packages to install") + 'names', nargs='*', help="Names of tests to run.") subparser.add_argument( '-l', '--list', action='store_true', dest='list', help="Show available tests") subparser.add_argument( @@ -17,24 +17,10 @@ def setup_parser(subparser): help="verbose output") -def find_test_modules(): - """Include all the modules under test, unless they set skip_test=True""" - for name in list_modules(spack.test_path): - module = __import__('spack.test.' + name, fromlist='skip_test') - if not getattr(module, 'skip_test', False): - yield name - - def test(parser, args): if args.list: print "Available tests:" - colify(find_test_modules()) - - elif not args.names: - for name in find_test_modules(): - print "Running Tests: %s" % name - spack.test.run(name, verbose=args.verbose) + colify(spack.test.list_tests(), indent=2) else: - for name in args.names: - spack.test.run(name, verbose=args.verbose) + spack.test.run(args.names, args.verbose) diff --git a/lib/spack/spack/test/__init__.py b/lib/spack/spack/test/__init__.py index 477ea4d581..22072d12d2 100644 --- a/lib/spack/spack/test/__init__.py +++ b/lib/spack/spack/test/__init__.py @@ -1,13 +1,58 @@ import sys import unittest + import spack +from spack.colify import colify +import spack.tty as tty + +test_names = ['versions', + 'url_parse', + 'stage', + 'spec_syntax', + 'spec_dag', + 'concretize'] + + +def list_tests(): + return test_names + + +def run(names, verbose=False): + verbosity = 1 if not verbose else 2 + + if not names: + names = test_names + else: + for test in names: + if test not in test_names: + tty.error("%s is not a valid spack test name." % test, + "Valid names are:") + colify(test_names, indent=4) + sys.exit(1) + + runner = unittest.TextTestRunner(verbosity=verbosity) + + testsRun = errors = failures = skipped = 0 + for test in names: + module = 'spack.test.' + test + suite = unittest.defaultTestLoader.loadTestsFromName(module) -def run(test_name, verbose=False): - __import__(__package__ + "." + test_name) + tty.msg("Running test: %s" % test) + result = runner.run(suite) + testsRun += result.testsRun + errors += len(result.errors) + failures += len(result.failures) + skipped += len(result.skipped) - # This just runs unittest.main on the module with the provided name - test_module = getattr(spack.test, test_name) + succeeded = not errors and not failures + tty.msg("Tests Complete.", + "%5d tests run" % testsRun, + "%5d skipped" % skipped, + "%5d failures" % failures, + "%5d errors" % errors) - verbosity=1 - if verbose: verbosity = 2 - unittest.main(module=test_module, argv=sys.argv[:1], verbosity=verbosity, exit=False) + if not errors and not failures: + tty.info("OK", format='g') + else: + tty.info("FAIL", format='r') + sys.exit(1) -- cgit v1.2.3-70-g09d2