diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-09-29 07:52:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-29 07:52:52 (GMT) |
commit | dac4ec52866e4068f3ac33b4da1e1a1fe6fc2cba (patch) | |
tree | 46d3f6069071f82e2aa3f70cea511a666e0e84ef /Lib/test/test_argparse.py | |
parent | 61180446eee2aef07b042c7e8892c45afabd1499 (diff) | |
download | cpython-dac4ec52866e4068f3ac33b4da1e1a1fe6fc2cba.zip cpython-dac4ec52866e4068f3ac33b4da1e1a1fe6fc2cba.tar.gz cpython-dac4ec52866e4068f3ac33b4da1e1a1fe6fc2cba.tar.bz2 |
gh-53834: Fix support of arguments with choices in argparse (GH-124495)
Positional arguments with nargs equal to '?' or '*' no longer check
default against choices.
Optional arguments with nargs equal to '?' no longer check const
against choices.
Diffstat (limited to 'Lib/test/test_argparse.py')
-rw-r--r-- | Lib/test/test_argparse.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 01dc99c..5c8f0ec 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -628,9 +628,9 @@ class TestOptionalsNargsOptional(ParserTestCase): Sig('-w', nargs='?'), Sig('-x', nargs='?', const=42), Sig('-y', nargs='?', default='spam'), - Sig('-z', nargs='?', type=int, const='42', default='84'), + Sig('-z', nargs='?', type=int, const='42', default='84', choices=[1, 2]), ] - failures = ['2'] + failures = ['2', '-z a', '-z 42', '-z 84'] successes = [ ('', NS(w=None, x=None, y='spam', z=84)), ('-w', NS(w=None, x=None, y='spam', z=84)), @@ -1027,8 +1027,8 @@ class TestPositionalsNargsZeroOrMore(ParserTestCase): class TestPositionalsNargsZeroOrMoreDefault(ParserTestCase): """Test a Positional that specifies unlimited nargs and a default""" - argument_signatures = [Sig('foo', nargs='*', default='bar')] - failures = ['-x'] + argument_signatures = [Sig('foo', nargs='*', default='bar', choices=['a', 'b'])] + failures = ['-x', 'bar', 'a c'] successes = [ ('', NS(foo='bar')), ('a', NS(foo=['a'])), @@ -1061,8 +1061,8 @@ class TestPositionalsNargsOptional(ParserTestCase): class TestPositionalsNargsOptionalDefault(ParserTestCase): """Tests an Optional Positional with a default value""" - argument_signatures = [Sig('foo', nargs='?', default=42)] - failures = ['-x', 'a b'] + argument_signatures = [Sig('foo', nargs='?', default=42, choices=['a', 'b'])] + failures = ['-x', 'a b', '42'] successes = [ ('', NS(foo=42)), ('a', NS(foo='a')), @@ -1075,9 +1075,9 @@ class TestPositionalsNargsOptionalConvertedDefault(ParserTestCase): """ argument_signatures = [ - Sig('foo', nargs='?', type=int, default='42'), + Sig('foo', nargs='?', type=int, default='42', choices=[1, 2]), ] - failures = ['-x', 'a b', '1 2'] + failures = ['-x', 'a b', '1 2', '42'] successes = [ ('', NS(foo=42)), ('1', NS(foo=1)), |