annotate tests/testall.py @ 1:7f92e207830b default tip

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