annotate tests/testall.py @ 27:22218d90d33f

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