mirror of
https://github.com/python/cpython.git
synced 2025-08-28 04:35:02 +00:00
Issue #14910: Add allow_abbrev parameter to argparse.ArgumentParser.
Patch by Jonathan Paugh, Steven Bethard, paul j3 and Daniel Eriksson.
This commit is contained in:
parent
0fe6325acf
commit
8089cd642f
5 changed files with 95 additions and 20 deletions
|
@ -753,6 +753,39 @@ class TestOptionalsActionCount(ParserTestCase):
|
|||
]
|
||||
|
||||
|
||||
class TestOptionalsAllowLongAbbreviation(ParserTestCase):
|
||||
"""Allow long options to be abbreviated unambiguously"""
|
||||
|
||||
argument_signatures = [
|
||||
Sig('--foo'),
|
||||
Sig('--foobaz'),
|
||||
Sig('--fooble', action='store_true'),
|
||||
]
|
||||
failures = ['--foob 5', '--foob']
|
||||
successes = [
|
||||
('', NS(foo=None, foobaz=None, fooble=False)),
|
||||
('--foo 7', NS(foo='7', foobaz=None, fooble=False)),
|
||||
('--fooba a', NS(foo=None, foobaz='a', fooble=False)),
|
||||
('--foobl --foo g', NS(foo='g', foobaz=None, fooble=True)),
|
||||
]
|
||||
|
||||
|
||||
class TestOptionalsDisallowLongAbbreviation(ParserTestCase):
|
||||
"""Do not allow abbreviations of long options at all"""
|
||||
|
||||
parser_signature = Sig(allow_abbrev=False)
|
||||
argument_signatures = [
|
||||
Sig('--foo'),
|
||||
Sig('--foodle', action='store_true'),
|
||||
Sig('--foonly'),
|
||||
]
|
||||
failures = ['-foon 3', '--foon 3', '--food', '--food --foo 2']
|
||||
successes = [
|
||||
('', NS(foo=None, foodle=False, foonly=None)),
|
||||
('--foo 3', NS(foo='3', foodle=False, foonly=None)),
|
||||
('--foonly 7 --foodle --foo 2', NS(foo='2', foodle=True, foonly='7')),
|
||||
]
|
||||
|
||||
# ================
|
||||
# Positional tests
|
||||
# ================
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue