summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_argparse.py
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2015-02-13 23:39:17 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2015-02-13 23:39:17 (GMT)
commit8089cd642fa8b29e852506218b6355be064c2bd5 (patch)
tree5e1898e258a592415b0b6dd22ebbc527641c514c /Lib/test/test_argparse.py
parent0fe6325acf013c945dc003eae2ab5addc2186645 (diff)
downloadcpython-8089cd642fa8b29e852506218b6355be064c2bd5.zip
cpython-8089cd642fa8b29e852506218b6355be064c2bd5.tar.gz
cpython-8089cd642fa8b29e852506218b6355be064c2bd5.tar.bz2
Issue #14910: Add allow_abbrev parameter to argparse.ArgumentParser.
Patch by Jonathan Paugh, Steven Bethard, paul j3 and Daniel Eriksson.
Diffstat (limited to 'Lib/test/test_argparse.py')
-rw-r--r--Lib/test/test_argparse.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
index a0b9162..d7f90cd 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -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
# ================