diff options
author | Ali Hamdan <ali.hamdan.dev@gmail.com> | 2024-08-07 13:20:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-07 13:20:38 (GMT) |
commit | 013a0929750ed2b46ae990b59d02e3db84337474 (patch) | |
tree | 4a176cf43a56a10d64fc99903d55d16717332eba /Lib/test | |
parent | 9e551f9b351440ebae79e07a02d0e4a1b61d139e (diff) | |
download | cpython-013a0929750ed2b46ae990b59d02e3db84337474.zip cpython-013a0929750ed2b46ae990b59d02e3db84337474.tar.gz cpython-013a0929750ed2b46ae990b59d02e3db84337474.tar.bz2 |
gh-121151: argparse: Fix wrapping of long usage text of arguments inside a mutually exclusive groups (GH-121159)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_argparse.py | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 84fe74a..fd111be 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -2959,12 +2959,12 @@ class TestMutuallyExclusiveLong(MEMixin, TestCase): ] usage_when_not_required = '''\ - usage: PROG [-h] [--abcde ABCDE] [--fghij FGHIJ] - [--klmno KLMNO | --pqrst PQRST] + usage: PROG [-h] [--abcde ABCDE] [--fghij FGHIJ] [--klmno KLMNO | + --pqrst PQRST] ''' usage_when_required = '''\ - usage: PROG [-h] [--abcde ABCDE] [--fghij FGHIJ] - (--klmno KLMNO | --pqrst PQRST) + usage: PROG [-h] [--abcde ABCDE] [--fghij FGHIJ] (--klmno KLMNO | + --pqrst PQRST) ''' help = '''\ @@ -4347,6 +4347,24 @@ class TestHelpUsageNoWhitespaceCrash(TestCase): ''') self.assertEqual(parser.format_usage(), usage) + def test_long_mutex_groups_wrap(self): + parser = argparse.ArgumentParser(prog='PROG') + g = parser.add_mutually_exclusive_group() + g.add_argument('--op1', metavar='MET', nargs='?') + g.add_argument('--op2', metavar=('MET1', 'MET2'), nargs='*') + g.add_argument('--op3', nargs='*') + g.add_argument('--op4', metavar=('MET1', 'MET2'), nargs='+') + g.add_argument('--op5', nargs='+') + g.add_argument('--op6', nargs=3) + g.add_argument('--op7', metavar=('MET1', 'MET2', 'MET3'), nargs=3) + + usage = textwrap.dedent('''\ + usage: PROG [-h] [--op1 [MET] | --op2 [MET1 [MET2 ...]] | --op3 [OP3 ...] | + --op4 MET1 [MET2 ...] | --op5 OP5 [OP5 ...] | --op6 OP6 OP6 OP6 | + --op7 MET1 MET2 MET3] + ''') + self.assertEqual(parser.format_usage(), usage) + class TestHelpVariableExpansion(HelpTestCase): """Test that variables are expanded properly in help messages""" |