From d08e0af9bf86e81d4a5b3dbbe38092bacc5edd62 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 11 Nov 2016 15:52:30 -0500 Subject: [PATCH 1/1] Build looping into the test suite and make doctests optional. --- makefile | 9 ++------- test/__init__.py | 23 ++++++++++++++++------- test/__main__.py | 30 +++++++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/makefile b/makefile index 9f9798b..49c43ce 100644 --- a/makefile +++ b/makefile @@ -16,14 +16,9 @@ doctest: check: PYTHONPATH="." test/__main__.py -.PHONE: checkloop +.PHONY: checkloop checkloop: - COUNT=0; \ - while [ $$? -eq 0 ]; do \ - COUNT=`expr $$COUNT + 1`; \ - echo $$COUNT; \ - PYTHONPATH="." test/__main__.py; \ - done; + PYTHONPATH="." test/__main__.py --no-doctests --loop .PHONY: lint lint: diff --git a/test/__init__.py b/test/__init__.py index 0f6f15c..2e23a7c 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -18,17 +18,26 @@ from test import matrices_test from test import randomgen from test import symmetric_linear_game_test -def build_suite(): +def build_suite(doctests=True): """ Build our test suite, separately from running it. + + Parameters + ---------- + + doctests : bool + Do you want to build the doctests, too? During random testing, + the answer may be "no." + """ suite = TestSuite() - suite.addTest(DocTestSuite(cones)) - suite.addTest(DocTestSuite(errors, optionflags=ELLIPSIS)) - suite.addTest(DocTestSuite(games, optionflags=ELLIPSIS)) - suite.addTest(DocTestSuite(matrices, optionflags=ELLIPSIS)) - suite.addTest(DocTestSuite(symmetric_linear_game_test)) - suite.addTest(DocTestSuite(randomgen, optionflags=ELLIPSIS)) + if doctests: + suite.addTest(DocTestSuite(cones)) + suite.addTest(DocTestSuite(errors, optionflags=ELLIPSIS)) + suite.addTest(DocTestSuite(games, optionflags=ELLIPSIS)) + suite.addTest(DocTestSuite(matrices, optionflags=ELLIPSIS)) + suite.addTest(DocTestSuite(symmetric_linear_game_test)) + suite.addTest(DocTestSuite(randomgen, optionflags=ELLIPSIS)) slg_tests = TestLoader().loadTestsFromModule(symmetric_linear_game_test) suite.addTest(slg_tests) mat_tests = TestLoader().loadTestsFromModule(matrices_test) diff --git a/test/__main__.py b/test/__main__.py index b0598e7..aca4e64 100755 --- a/test/__main__.py +++ b/test/__main__.py @@ -2,9 +2,33 @@ """ 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(): +# 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. +doctests = True +loop = False + +if "--no-doctests" in argv: + doctests = False + +if "--loop" in argv: + loop = True + +# Running the test suite clobbers it! And deepcopy() doesn't work on a +# suite that contains doctests! ARRRGRRGRRGRHG!!!!!! You're all idiots. +result = run_suite(build_suite(doctests)) + +if result.wasSuccessful() and not loop: exit(0) -else: - exit(1) + +if loop: + while(result.wasSuccessful()): + result = run_suite(build_suite(doctests)) + +exit(1) -- 2.44.2