# HG changeset patch # User Jeff Hammel # Date 1395462564 25200 # Node ID daf3a05a05fef42f6eca4ab6b73d8b30d5cfca0e # Parent 58eed691dca77b58ae23110fa627edcbfd71e45d STUB: tests/test.py diff -r 58eed691dca7 -r daf3a05a05fe tests/test.py --- a/tests/test.py Mon Nov 11 19:18:58 2013 -0800 +++ b/tests/test.py Fri Mar 21 21:29:24 2014 -0700 @@ -1,7 +1,7 @@ #!/usr/bin/env python """ -doctest runner for pyloader +run tests for pyloader """ import doctest @@ -9,25 +9,31 @@ import sys from optparse import OptionParser +directory = os.path.dirname(os.path.abspath(__file__)) -def run_tests(raise_on_error=False, report_first=False): +def gather(): + """ gather tests""" + return [test for test in os.listdir(directory) + if test.endswith('.txt')] + +def run_tests(tests=None, raise_on_error=False, report_first=False): + """run the tests""" # add results here results = {} # doctest arguments - directory = os.path.dirname(os.path.abspath(__file__)) extraglobs = {'here': directory} doctest_args = dict(extraglobs=extraglobs, raise_on_error=raise_on_error) if report_first: doctest_args['optionflags'] = doctest.REPORT_ONLY_FIRST_FAILURE # gather tests - tests = [ test for test in os.listdir(directory) - if test.endswith('.txt') ] + tests = tests or gather() # run the tests for test in tests: + print ("Running: " + test) try: results[test] = doctest.testfile(test, **doctest_args) except doctest.DocTestFailure, failure: @@ -40,7 +46,10 @@ def main(args=sys.argv[1:]): # parse command line args - parser = OptionParser() + parser = OptionParser(description=__doc__) + parser.add_option('--list', dest='list_tests', + action='store_true', default=False, + help="list tests and exit") parser.add_option('--raise', dest='raise_on_error', default=False, action='store_true', help="raise on first error") @@ -49,12 +58,19 @@ help="report the first error only (all tests will still run)") options, args = parser.parse_args(args) + # gathe tests + tests = gather() + + if options.list_tests: + print ("\n".join(tests)) + sys.exit() + # run the tests results = run_tests(report_first=options.report_first, raise_on_error=options.raise_on_error) if sum([i.failed for i in results.values()]): sys.exit(1) # error - + if __name__ == '__main__': main()