Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions Lib/test/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6028,15 +6028,16 @@ def test(arith=None, verbose=None, todo_tests=None, debug=None):


if __name__ == '__main__':
import optparse
p = optparse.OptionParser("test_decimal.py [--debug] [{--skip | test1 [test2 [...]]}]")
p.add_option('--debug', '-d', action='store_true', help='shows the test number and context before each test')
p.add_option('--skip', '-s', action='store_true', help='skip over 90% of the arithmetic tests')
(opt, args) = p.parse_args()

if opt.skip:
import argparse
parser = argparse.ArgumentParser(usage="test_decimal.py [--debug] [{--skip | test1 [test2 [...]]}]")
Comment on lines +6031 to +6032
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let argparse generate the usage, and it'll use colour for the different parts. And put the positional arg first, to match help output:

Suggested change
import argparse
parser = argparse.ArgumentParser(usage="test_decimal.py [--debug] [{--skip | test1 [test2 [...]]}]")
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("tests", nargs="*", help="specific tests to run")

parser.add_argument('--debug', '-d', action='store_true', help='shows the test number and context before each test')
parser.add_argument('--skip', '-s', action='store_true', help='skip over 90%% of the arithmetic tests')
Comment on lines +6033 to +6034
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The short option usually goes before the long, and this matches -h, --help. Also wrap long lines:

Suggested change
parser.add_argument('--debug', '-d', action='store_true', help='shows the test number and context before each test')
parser.add_argument('--skip', '-s', action='store_true', help='skip over 90%% of the arithmetic tests')
parser.add_argument(
"-d",
"--debug",
action="store_true",
help="shows the test number and context before each test",
)
parser.add_argument(
"-s",
"--skip",
action="store_true",
help="skip over 90%% of the arithmetic tests",
)`

parser.add_argument('tests', nargs='*', help='specific tests to run')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
parser.add_argument('tests', nargs='*', help='specific tests to run')

args = parser.parse_args()

if args.skip:
test(arith=False, verbose=True)
elif args:
test(arith=True, verbose=True, todo_tests=args, debug=opt.debug)
elif args.tests:
test(arith=True, verbose=True, todo_tests=args.tests, debug=args.debug)
else:
test(arith=True, verbose=True)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace the usage of the deprecated optparse module with argparse in Lib/test/test_decimal.py.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the issue, optparse is no longer deprecated.

Suggested change
Replace the usage of the deprecated optparse module with argparse in Lib/test/test_decimal.py.
Replace :mod:`optparse` with :mod:`argparse` in ``Lib/test/test_decimal.py``.

Loading