Skip to content

Commit

Permalink
Use argparse for bin/doctest
Browse files Browse the repository at this point in the history
  • Loading branch information
sylee957 committed May 13, 2020
1 parent 6b6143a commit 73088e0
Showing 1 changed file with 37 additions and 34 deletions.
71 changes: 37 additions & 34 deletions bin/doctest
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,51 @@ blacklist = []

import sys
import os
from optparse import OptionParser
from argparse import ArgumentParser
import re

from get_sympy import path_hack
path_hack()

parser = OptionParser()
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
default=False)

# if you don't see a -n `default=False`;
# if you do see a -n `store_true` means to store a True value for it;
# dest is where in options to put it, options.normal will hold the bool;
# when the user enters -h or --help, print the `help` text
parser.add_option("-n", "--normal", action="store_true", dest="normal",
help="run normal doctests; do not require explicit imports", default=False)
parser.add_option('-t', '--types', dest='types', action='store',
default=None, choices=['gmpy', 'gmpy1', 'python'],
help='setup ground types: gmpy | gmpy1 | python')
parser.add_option("--no-colors", action="store_false", dest="colors",
default=True, help="Do not report colored [OK] and [FAIL]")
parser.add_option("--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_option('-C', '--no-cache', dest='cache', action='store_false',
default=True, help='disable caching mechanism')
parser.add_option("--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_option('--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_option('--rerun', action="store", dest="rerun",
default=0, help="Number of times to rerun the specified tests",
type='int')
parser.set_usage("test [options ...] [files ...]")
parser.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).\
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).
"""

options, args = parser.parse_args()
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:
Expand Down

0 comments on commit 73088e0

Please sign in to comment.