comparison tests/test.py @ 87:29ca60f428cc

STUB: tests/test.py tests/test_include.txt
author Jeff Hammel <k0scist@gmail.com>
date Fri, 21 Mar 2014 22:27:51 -0700
parents daf3a05a05fe
children
comparison
equal deleted inserted replaced
86:2c315267390b 87:29ca60f428cc
2 2
3 """ 3 """
4 run tests for pyloader 4 run tests for pyloader
5 """ 5 """
6 6
7 # imports
8 import argparse
7 import doctest 9 import doctest
8 import os 10 import os
9 import sys 11 import sys
10 from optparse import OptionParser
11 12
12 directory = os.path.dirname(os.path.abspath(__file__)) 13 directory = os.path.dirname(os.path.abspath(__file__))
13 14
14 def gather(): 15 def gather():
15 """ gather tests""" 16 """ gather tests"""
42 raise failure.exc_info[0], failure.exc_info[1], failure.exc_info[2] 43 raise failure.exc_info[0], failure.exc_info[1], failure.exc_info[2]
43 44
44 return results 45 return results
45 46
46 def main(args=sys.argv[1:]): 47 def main(args=sys.argv[1:]):
48 """test runner CLI"""
47 49
48 # parse command line args 50 # parse command line args
49 parser = OptionParser(description=__doc__) 51 parser = argparse.ArgumentParser(description=__doc__)
50 parser.add_option('--list', dest='list_tests', 52 parser.add_argument('tests', metavar='test', nargs="*",
51 action='store_true', default=False, 53 help="tests to run; if omitted, run all")
52 help="list tests and exit") 54 parser.add_argument('--list', dest='list_tests',
53 parser.add_option('--raise', dest='raise_on_error', 55 action='store_true', default=False,
54 default=False, action='store_true', 56 help="list tests and exit")
55 help="raise on first error") 57 parser.add_argument('--raise', dest='raise_on_error',
56 parser.add_option('--report-first', dest='report_first', 58 default=False, action='store_true',
57 default=False, action='store_true', 59 help="raise on first error")
58 help="report the first error only (all tests will still run)") 60 parser.add_argument('--report-first', dest='report_first',
59 options, args = parser.parse_args(args) 61 default=False, action='store_true',
62 help="report the first error only (all tests will still run)")
63 options = parser.parse_args(args)
60 64
61 # gathe tests 65 # gather tests
62 tests = gather() 66 tests = gather()
67
68 # filter tests
69 if options.tests:
70 missing = set(options.tests).difference(tests)
71 if missing:
72 parser.error("Test files not found: {0}; Should be in {1}".format(', '.join(missing),
73 ', '.join(tests)))
74 tests = options.tests
63 75
64 if options.list_tests: 76 if options.list_tests:
65 print ("\n".join(tests)) 77 print ("\n".join(tests))
66 sys.exit() 78 sys.exit()
67 79
68 # run the tests 80 # run the tests
69 results = run_tests(report_first=options.report_first, 81 results = run_tests(tests=tests,
82 report_first=options.report_first,
70 raise_on_error=options.raise_on_error) 83 raise_on_error=options.raise_on_error)
71 if sum([i.failed for i in results.values()]): 84 if sum([i.failed for i in results.values()]):
72 sys.exit(1) # error 85 sys.exit(1) # error
73 86
74 87