annotate tests/test.py @ 84:daf3a05a05fe

STUB: tests/test.py
author Jeff Hammel <k0scist@gmail.com>
date Fri, 21 Mar 2014 21:29:24 -0700
parents ff272dcd5cd8
children 29ca60f428cc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 """
84
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
4 run tests 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
84
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
12 directory = os.path.dirname(os.path.abspath(__file__))
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
13
84
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
14 def gather():
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
15 """ gather tests"""
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
16 return [test for test in os.listdir(directory)
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
17 if test.endswith('.txt')]
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
18
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
19 def run_tests(tests=None, raise_on_error=False, report_first=False):
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
20 """run the tests"""
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
21
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 # 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
23 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
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 # 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
26 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
27 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
28 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
29 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
30
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 # gather tests
84
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
32 tests = tests or gather()
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
33
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 # 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
35 for test in tests:
84
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
36 print ("Running: " + test)
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
37 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
38 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
39 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
40 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
41 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
42 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
43
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 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
45
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 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
47
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 # parse command line args
84
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
49 parser = OptionParser(description=__doc__)
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
50 parser.add_option('--list', dest='list_tests',
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
51 action='store_true', default=False,
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
52 help="list tests and exit")
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
53 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
54 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
55 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
56 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
57 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
58 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
59 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
60
84
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
61 # gathe tests
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
62 tests = gather()
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
63
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
64 if options.list_tests:
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
65 print ("\n".join(tests))
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
66 sys.exit()
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
67
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
68 # 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
69 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
70 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
71 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
72 sys.exit(1) # error
84
daf3a05a05fe STUB: tests/test.py
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
73
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
74
a825f00fe062 add a different call method, rename the old one, and have a test for it
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
75 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
76 main()