Mercurial > hg > FileServer
annotate tests/test.py @ 34:aca8cb6bfd63 default tip
fix documentation + bump version
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Mon, 05 Mar 2012 14:09:43 -0800 |
| parents | f00fcf6d9f1d |
| children |
| rev | line source |
|---|---|
| 0 | 1 #!/usr/bin/env python |
| 2 | |
| 3 """ | |
| 4 doctest runner | |
| 5 """ | |
| 6 | |
| 7 import doctest | |
| 8 import os | |
| 9 import sys | |
| 10 from optparse import OptionParser | |
| 11 | |
| 12 def run_tests(raise_on_error=False, report_first=False): | |
| 13 | |
| 14 # add results here | |
| 15 results = {} | |
| 16 | |
| 17 # doctest arguments | |
| 18 directory = os.path.dirname(os.path.abspath(__file__)) | |
| 19 extraglobs = {'here': directory} | |
| 31 | 20 doctest_args = dict(extraglobs=extraglobs, raise_on_error=raise_on_error, ) |
| 21 doctest_args['optionflags'] = doctest.ELLIPSIS | |
| 0 | 22 if report_first: |
| 31 | 23 doctest_args['optionflags'] |= doctest.REPORT_ONLY_FIRST_FAILURE |
| 0 | 24 |
| 25 # gather tests | |
|
7
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
26 tests = [test for test in os.listdir(directory) |
|
4d1852cfc077
rudimentary test for directory server
Jeff Hammel <jhammel@mozilla.com>
parents:
6
diff
changeset
|
27 if test.endswith('.txt')] |
| 0 | 28 |
| 29 # run the tests | |
| 30 for test in tests: | |
| 31 try: | |
| 32 results[test] = doctest.testfile(test, **doctest_args) | |
| 33 except doctest.DocTestFailure, failure: | |
| 34 raise | |
| 35 except doctest.UnexpectedException, failure: | |
| 36 raise failure.exc_info[0], failure.exc_info[1], failure.exc_info[2] | |
| 37 | |
| 38 return results | |
| 39 | |
| 40 def main(args=sys.argv[1:]): | |
| 41 | |
| 42 # parse command line args | |
| 43 parser = OptionParser(description=__doc__) | |
| 44 parser.add_option('--raise', dest='raise_on_error', | |
| 45 default=False, action='store_true', | |
| 46 help="raise on first error") | |
| 47 parser.add_option('--report-first', dest='report_first', | |
| 48 default=False, action='store_true', | |
| 49 help="report the first error only (all tests will still run)") | |
| 50 options, args = parser.parse_args(args) | |
| 51 | |
| 52 # run the tests | |
| 53 results = run_tests(**options.__dict__) | |
| 54 if sum([i.failed for i in results.values()]): | |
| 55 sys.exit(1) # error | |
| 56 | |
| 57 | |
| 58 if __name__ == '__main__': | |
| 59 main() | |
| 60 |
