annotate tests/testall.py @ 158:176aad184ad0

one more note to self
author Jeff Hammel <k0scist@gmail.com>
date Tue, 12 May 2015 16:51:10 -0700
parents 48d0f28311a3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3 """
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 run all unit tests
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 """
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7 import os
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 import sys
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 import unittest
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11 here = os.path.dirname(os.path.abspath(__file__))
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13 def main(args=sys.argv[1:]):
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15 results = unittest.TestResult()
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 suite = unittest.TestLoader().discover(here, 'test_*.py')
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
17 suite.run(results)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18 n_errors = len(results.errors)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
19 n_failures = len(results.failures)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
20 print ("Run {} tests ({} failures; {} errors)".format(results.testsRun,
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21 n_failures,
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
22 n_errors))
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
23 if results.wasSuccessful():
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
24 print ("Success")
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
25 sys.exit(0)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
26 else:
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27 # print failures and errors
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
28 for label, item in (('FAIL', results.failures),
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
29 ('ERROR', results.errors)):
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
30 if item:
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
31 print ("\n{}::\n".format(label))
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
32 for index, (i, message) in enumerate(item):
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
33 print ('{}) {}:'.format(index, str(i)))
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
34 print (message)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
35 sys.exit(1)
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
36
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
37 if __name__ == '__main__':
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
38 main()
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
39
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
40