]> gitweb.michael.orlitzky.com - dunshire.git/blob - test/__main__.py
test: add the ability to run the test suite verbosely.
[dunshire.git] / test / __main__.py
1 #!/usr/bin/env python
2 """
3 An implementation of __main__() that allows us to "run this module."
4 """
5 from sys import argv
6
7 from test import build_suite, run_suite
8
9
10 def main(doctests, loop, verbose):
11 """
12 The main function for this module. It runs the tests.
13
14 We take two command-line arguments. The first enables you to turn
15 off the doctests, which are deterministic. The second tells us to
16 repeat the test suite indefinitely rather than return the result of
17 running it once. The flags usually occur together so that we don't
18 waste time running the doctests in a loop.
19
20 Parameters
21 ----------
22
23 doctests : bool
24 Do you want to run the doctests?
25
26 loop : bool
27 Do you want to loop and rerun the tests indefinitely?
28
29 verbose : bool
30 Do you want to see the name and result of each test as
31 it is run?
32
33 """
34 # Running the test suite clobbers it! And deepcopy() doesn't work
35 # on a suite that contains doctests! ARRRGRRGRRGRHG!!!!!! You're all
36 # idiots.
37 verbosity = 1
38 if verbose: verbosity = 2
39 result = run_suite(build_suite(doctests), verbosity)
40
41 if result.wasSuccessful() and not loop:
42 return 0
43
44 if loop:
45 passed = 0
46 while result.wasSuccessful():
47 print('Passed: {:d}'.format(passed))
48 passed += 1
49 result = run_suite(build_suite(doctests), verbosity)
50
51 return 1
52
53
54 if __name__ == '__main__':
55 doctests = not "--no-doctests" in argv
56 loop = '--loop' in argv
57 verbose = '--verbose' in argv
58 exit(main(doctests, loop, verbose))