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