forked from sympy/sympy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoctest
executable file
·85 lines (71 loc) · 2.93 KB
/
doctest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
"""
Program to execute doctests using the py.test like interface.
The advantage over py.test is that it only depends on sympy and should just
work in any circumstances. See "sympy.doctest?" for documentation.
"""
from __future__ import print_function
# files listed here can be in unix forward slash format with paths
# listed relative to sympy (which contains bin, etc...)
blacklist = []
import sys
import os
from argparse import ArgumentParser
import re
from get_sympy import path_hack
path_hack()
epilog = """
"options" are any of the options above.
"files" are 0 or more glob strings of files to run doctests on.
If no file arguments are given, all doctests will be run.
This program runs both doctests in the source and doctests in the Sphinx
documentation (doc/src/ directory).
"""
parser = ArgumentParser(epilog=epilog)
parser.add_argument(
"-v", "--verbose", action="store_true", dest="verbose", default=False)
parser.add_argument(
"-n", "--normal", action="store_true", dest="normal", default=False,
help="run normal doctests; do not require explicit imports")
parser.add_argument(
'-t', '--types', dest='types', action='store', default=None,
choices=['gmpy', 'gmpy1', 'python'],
help='Setup ground types')
parser.add_argument(
"--no-colors", action="store_false", dest="colors", default=True,
help="Do not report colored [OK] and [FAIL]")
parser.add_argument(
"--force-colors", action="store_true", dest="force_colors", default=False,
help="Always use colors, even if the output is not to a terminal.")
parser.add_argument(
'-C', '--no-cache', dest='cache', action='store_false', default=True,
help='Disable caching mechanism.')
parser.add_argument(
"--no-subprocess", action="store_false", dest="subprocess", default=True,
help="Don't run the tests in a separate subprocess. "
"This may prevent hash randomization from being enabled.")
parser.add_argument(
'--split', action="store", type=str, default=None,
help="Only run part of the doctests. Should be of the form a/b, e.g., 1/2")
parser.add_argument(
'--rerun', action="store", dest="rerun", default=0,
help="Number of times to rerun the specified tests", type=int)
options, args = parser.parse_known_args()
# Check this again here to give a better error message
if options.split:
sp = re.compile(r'([0-9]+)/([1-9][0-9]*)')
if not sp.match(options.split):
parser.error("option --split: must be of the form a/b where a and b "
"are integers, not %r" % options.split)
if not options.cache:
os.environ['SYMPY_USE_CACHE'] = 'no'
if options.types:
os.environ['SYMPY_GROUND_TYPES'] = options.types
import sympy
ok = sympy.doctest(*args, verbose=options.verbose, blacklist=blacklist,
normal=options.normal, subprocess=options.subprocess, split=options.split,
rerun=options.rerun, colors=options.colors, force_colors=options.force_colors)
if ok:
sys.exit(0)
else:
sys.exit(1)