summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_argparse.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_argparse.py')
-rw-r--r--Lib/test/test_argparse.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
index 60bf199..b095783 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -810,6 +810,23 @@ class TestOptionalsDisallowLongAbbreviation(ParserTestCase):
]
+class TestOptionalsDisallowLongAbbreviationPrefixChars(ParserTestCase):
+ """Disallowing abbreviations works with alternative prefix characters"""
+
+ parser_signature = Sig(prefix_chars='+', 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')),
+ ]
+
+
class TestDisallowLongAbbreviationAllowsShortGrouping(ParserTestCase):
"""Do not allow abbreviations of long options at all"""
@@ -828,6 +845,26 @@ class TestDisallowLongAbbreviationAllowsShortGrouping(ParserTestCase):
('-ccrcc', NS(r='cc', c=2)),
]
+
+class TestDisallowLongAbbreviationAllowsShortGroupingPrefix(ParserTestCase):
+ """Short option grouping works with custom prefix and allow_abbrev=False"""
+
+ parser_signature = Sig(prefix_chars='+', allow_abbrev=False)
+ argument_signatures = [
+ Sig('+r'),
+ Sig('+c', action='count'),
+ ]
+ failures = ['+r', '+c +r']
+ successes = [
+ ('', NS(r=None, c=None)),
+ ('+ra', NS(r='a', c=None)),
+ ('+rcc', NS(r='cc', c=None)),
+ ('+cc', NS(r=None, c=2)),
+ ('+cc +ra', NS(r='a', c=2)),
+ ('+ccrcc', NS(r='cc', c=2)),
+ ]
+
+
# ================
# Positional tests
# ================