annotate tests/testall.py @ 55:4e2190495d50

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