annotate tests/testall.py @ 3:350e4298e116

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