annotate makeitso/python_package/tests/testall.py @ 232:66ca1a67a76c

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