annotate tests/testall.py @ 0:dc90512b9c98

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