# HG changeset patch # User Jeff Hammel # Date 1395466071 25200 # Node ID 29ca60f428cca7a4ad5afb46f862219f30e1b270 # Parent 2c315267390b27db95227d45d230f2d272ba5c30 STUB: tests/test.py tests/test_include.txt diff -r 2c315267390b -r 29ca60f428cc tests/test.py --- a/tests/test.py Fri Mar 21 22:04:17 2014 -0700 +++ b/tests/test.py Fri Mar 21 22:27:51 2014 -0700 @@ -4,10 +4,11 @@ run tests for pyloader """ +# imports +import argparse import doctest import os import sys -from optparse import OptionParser directory = os.path.dirname(os.path.abspath(__file__)) @@ -44,29 +45,41 @@ return results def main(args=sys.argv[1:]): + """test runner CLI""" # parse command line args - 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") - parser.add_option('--report-first', dest='report_first', - default=False, action='store_true', - help="report the first error only (all tests will still run)") - options, args = parser.parse_args(args) + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('tests', metavar='test', nargs="*", + help="tests to run; if omitted, run all") + parser.add_argument('--list', dest='list_tests', + action='store_true', default=False, + help="list tests and exit") + parser.add_argument('--raise', dest='raise_on_error', + default=False, action='store_true', + help="raise on first error") + parser.add_argument('--report-first', dest='report_first', + default=False, action='store_true', + help="report the first error only (all tests will still run)") + options = parser.parse_args(args) - # gathe tests + # gather tests tests = gather() + # filter tests + if options.tests: + missing = set(options.tests).difference(tests) + if missing: + parser.error("Test files not found: {0}; Should be in {1}".format(', '.join(missing), + ', '.join(tests))) + tests = options.tests + if options.list_tests: print ("\n".join(tests)) sys.exit() # run the tests - results = run_tests(report_first=options.report_first, + results = run_tests(tests=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 diff -r 2c315267390b -r 29ca60f428cc tests/test_include.txt --- a/tests/test_include.txt Fri Mar 21 22:04:17 2014 -0700 +++ b/tests/test_include.txt Fri Mar 21 22:27:51 2014 -0700 @@ -1,6 +1,9 @@ Test IniFactory =============== -Let's test the .ini factory:: +Let's test file inclusion. First a simple example without it for comparison:: >>> import os + >>> from pyloader.factory import IniFactory + >>> inifile = os.path.join(here, 'test.ini') + >>> inifactory = IniFactory(inifile)