bpo-37880: for argparse add_argument with action='store_const', const now defaults to None. (GH-26707)

This commit is contained in:
Jack DeVries 2021-07-31 12:27:55 -04:00 committed by GitHub
parent 1cf8424a62
commit 0ad173249d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 13 deletions

View file

@ -745,6 +745,25 @@ class TestOptionalsActionAppendWithDefault(ParserTestCase):
]
class TestConstActionsMissingConstKwarg(ParserTestCase):
"""Tests that const gets default value of None when not provided"""
argument_signatures = [
Sig('-f', action='append_const'),
Sig('--foo', action='append_const'),
Sig('-b', action='store_const'),
Sig('--bar', action='store_const')
]
failures = ['-f v', '--foo=bar', '--foo bar']
successes = [
('', NS(f=None, foo=None, b=None, bar=None)),
('-f', NS(f=[None], foo=None, b=None, bar=None)),
('--foo', NS(f=None, foo=[None], b=None, bar=None)),
('-b', NS(f=None, foo=None, b=None, bar=None)),
('--bar', NS(f=None, foo=None, b=None, bar=None)),
]
class TestOptionalsActionAppendConst(ParserTestCase):
"""Tests the append_const action for an Optional"""