X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=test%2F__main__.py;h=c8f0f24369debd78bf06b0e4c16f441e16858b67;hb=4a9928501f79549742c2e335742ddc65040f744f;hp=b0598e7dbbff4fa082039b4c41bff1604e8c2506;hpb=4436c4f4742b29c1e6eed699d11e05bc9e1f8414;p=dunshire.git diff --git a/test/__main__.py b/test/__main__.py index b0598e7..c8f0f24 100755 --- a/test/__main__.py +++ b/test/__main__.py @@ -2,9 +2,57 @@ """ An implementation of __main__() that allows us to "run this module." """ +from sys import argv + from test import build_suite, run_suite -if run_suite(build_suite()).wasSuccessful(): - exit(0) -else: - exit(1) + +def main(doctests, loop, verbose): + """ + The main function for this module. It runs the tests. + + We take two command-line arguments. The first enables you to turn + off the doctests, which are deterministic. The second tells us to + repeat the test suite indefinitely rather than return the result of + running it once. The flags usually occur together so that we don't + waste time running the doctests in a loop. + + Parameters + ---------- + + doctests : bool + Do you want to run the doctests? + + loop : bool + Do you want to loop and rerun the tests indefinitely? + + verbose : bool + Do you want to see the name and result of each test as + it is run? + + """ + # Running the test suite clobbers it! And deepcopy() doesn't work + # on a suite that contains doctests! ARRRGRRGRRGRHG!!!!!! You're all + # idiots. + verbosity = 1 + if verbose: verbosity = 2 + result = run_suite(build_suite(doctests), verbosity) + + if result.wasSuccessful() and not loop: + return 0 + + if loop: + passed = 0 + while result.wasSuccessful(): + print('Passed: {:d}'.format(passed)) + passed += 1 + result = run_suite(build_suite(doctests), verbosity) + + return 1 + + +if __name__ == '__main__': + doctests = not "--no-doctests" in argv + loop = '--loop' in argv + verbose = '--verbose' in argv + exit(main(doctests, loop, verbose))