diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-10-12 12:15:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-12 12:15:37 (GMT) |
commit | 63cf4e914f879ee28a75c02e867baa7c6047ea2b (patch) | |
tree | 88de7ebc06e68a4dd9e088e0249653427d675878 /Lib/test/test_argparse.py | |
parent | 07c2d15977738165e9dc4248e7edda7c75ecc14b (diff) | |
download | cpython-63cf4e914f879ee28a75c02e867baa7c6047ea2b.zip cpython-63cf4e914f879ee28a75c02e867baa7c6047ea2b.tar.gz cpython-63cf4e914f879ee28a75c02e867baa7c6047ea2b.tar.bz2 |
gh-125254: Fix error report about ambiguous option in argparse (GH-125273)
This was a regression introduced in gh-58573. It was only tested for the
case when the ambiguous option is the last argument in the command line.
Diffstat (limited to 'Lib/test/test_argparse.py')
-rw-r--r-- | Lib/test/test_argparse.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 61ddb5f..1fc97de 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -6730,9 +6730,19 @@ class TestExitOnError(TestCase): def test_ambiguous_option(self): self.parser.add_argument('--foobaz') self.parser.add_argument('--fooble', action='store_true') + self.parser.add_argument('--foogle') self.assertRaisesRegex(argparse.ArgumentError, - "ambiguous option: --foob could match --foobaz, --fooble", - self.parser.parse_args, ['--foob']) + "ambiguous option: --foob could match --foobaz, --fooble", + self.parser.parse_args, ['--foob']) + self.assertRaisesRegex(argparse.ArgumentError, + "ambiguous option: --foob=1 could match --foobaz, --fooble$", + self.parser.parse_args, ['--foob=1']) + self.assertRaisesRegex(argparse.ArgumentError, + "ambiguous option: --foob could match --foobaz, --fooble$", + self.parser.parse_args, ['--foob', '1', '--foogle', '2']) + self.assertRaisesRegex(argparse.ArgumentError, + "ambiguous option: --foob=1 could match --foobaz, --fooble$", + self.parser.parse_args, ['--foob=1', '--foogle', '2']) def test_os_error(self): self.parser.add_argument('file') |