]> gitweb.michael.orlitzky.com - dunshire.git/blob - test/__init__.py
Build looping into the test suite and make doctests optional.
[dunshire.git] / test / __init__.py
1 """
2 The whole test suite.
3
4 This module compiles the doctests and unittests from the rest of the
5 codebase into one big TestSuite() and the runs it. It also provides a
6 function :func:`build_suite` that merely builds the suite; the result
7 can be used by setuptools.
8 """
9
10 from unittest import TestLoader, TestSuite, TextTestRunner
11 from doctest import DocTestSuite, ELLIPSIS
12
13 from dunshire import cones
14 from dunshire import errors
15 from dunshire import matrices
16 from dunshire import games
17 from test import matrices_test
18 from test import randomgen
19 from test import symmetric_linear_game_test
20
21 def build_suite(doctests=True):
22 """
23 Build our test suite, separately from running it.
24
25 Parameters
26 ----------
27
28 doctests : bool
29 Do you want to build the doctests, too? During random testing,
30 the answer may be "no."
31
32 """
33 suite = TestSuite()
34 if doctests:
35 suite.addTest(DocTestSuite(cones))
36 suite.addTest(DocTestSuite(errors, optionflags=ELLIPSIS))
37 suite.addTest(DocTestSuite(games, optionflags=ELLIPSIS))
38 suite.addTest(DocTestSuite(matrices, optionflags=ELLIPSIS))
39 suite.addTest(DocTestSuite(symmetric_linear_game_test))
40 suite.addTest(DocTestSuite(randomgen, optionflags=ELLIPSIS))
41 slg_tests = TestLoader().loadTestsFromModule(symmetric_linear_game_test)
42 suite.addTest(slg_tests)
43 mat_tests = TestLoader().loadTestsFromModule(matrices_test)
44 suite.addTest(mat_tests)
45 return suite
46
47 def run_suite(suite):
48 """
49 Run all of the unit and doctests for the ``dunshire`` and ``test``
50 packages.
51 """
52 runner = TextTestRunner(verbosity=1)
53 return runner.run(suite)