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