From 0a34996131fa198c7b41e1a08e7244d57ec4220b Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Thu, 24 Jul 2008 18:36:41 +0200 Subject: [PATCH] gitstats: Added a module to dispatch unit-testing commands This should be the last part needed for a fully working unit-testing framework around GitStats that shows it's output in a format like the git regression test suite. --- src/git_stats/tests.py | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100755 src/git_stats/tests.py diff --git a/src/git_stats/tests.py b/src/git_stats/tests.py new file mode 100755 index 0000000..6f96432 --- /dev/null +++ b/src/git_stats/tests.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python + +import sys +import os + +from optparse import OptionParser + +from git_stats import testing +from git_stats import config_tests + +all_modules = { + } + +def dispatch(*args): + """Dispatches test related commands + """ + + progname = os.path.basename(sys.argv[0]) + " test" + parser = OptionParser(prog=progname) + + parser.add_option( + "-a", "--all", + action="store_true", + help="run tests for all known modules") + + parser.add_option( + "-m", "--module", + help="run the tests defined in the specified module") + + parser.add_option( + "-s", "--single", + metavar="TEST", + help="run only the tests for the specified module") + + parser.add_option( + "-t", "--tests", + metavar="TESTS", + action="store_true", + help="run only the specified tests") + + parser.add_option( + "-v", "--verbose", + action="store_true", + help="enable verbose output") + + if not args: + args.append("--help") + + options, args = parser.parse_args(list(args)) + + tests = [] + modules = [] + + # Add all modules we know about + if options.all: + tests.extend(all_modules.keys()) + + # Add only one test + if options.single: + tests.append(options.single) + + # Also add all tests as specified as command arguments + if options.tests: + tests.extend(args) + + if options.module: + try: + module = __import__("git_stats." + options.module, fromlist=True) + except ImportError, e: + parser.error("Could not import module '%s'.\n%s" % ( + options.module, str(e))) + + modules.append(module) + + for test in tests: + if not test in all_modules: + parser.error("Unknown module '%s'." % test) + + module = all_modules[test] + modules.append(module) + + if not modules: + parser.error("Please specify which modules to test") + + classes = [] + + for module in modules: + module_classes = module.getTestClasses() + classes.extend(module_classes) + + runner = testing.GitTestRunner() + res = runner.runTests(options, classes) + + return res + -- 2.11.4.GIT