diff -r 3ab32f7add6e Lib/test/test_argparse.py --- a/Lib/test/test_argparse.py Fri Aug 19 18:59:15 2016 +0200 +++ b/Lib/test/test_argparse.py Fri Aug 19 13:31:17 2016 -0500 @@ -1847,16 +1847,24 @@ if subparser_help: parser4_kwargs['help'] = 'lost help' parser4 = subparsers.add_parser('lost', **parser4_kwargs) - parser4.add_argument('-w', type=int, help='w help') - parser4.add_argument('x', choices='abc', help='x help') - - # add fifth sub-parser, with longer name (to test abbreviations) + parser4.add_argument('-r', type=int, help='r help') + parser4.add_argument('s', choices='abc', help='s help') + + # add fifth sub-parser, with different name (to test abbreviations) parser5_kwargs = dict(description='long description') if subparser_help: parser5_kwargs['help'] = 'long help' parser5 = subparsers.add_parser('long', **parser5_kwargs) - parser5.add_argument('-w', type=int, help='w help') - parser5.add_argument('x', choices='abc', help='x help') + parser5.add_argument('-p', type=int, help='p help') + parser5.add_argument('q', choices='abc', help='q help') + + # add sixth sub-parser, with longer name (to test abbreviations) + parser6_kwargs = dict(description='longer description') + if subparser_help: + parser6_kwargs['help'] = 'longer help' + parser6 = subparsers.add_parser('longer', **parser6_kwargs) + parser6.add_argument('-n', type=int, help='n help') + parser6.add_argument('o', choices='abc', help='o help') # return the main parser return parser @@ -1876,20 +1884,24 @@ def test_parse_args_abbreviation(self): # check some non-failure cases: self.assertEqual( - self.parser.parse_args('0.5 long b -w 7'.split()), - NS(foo=False, bar=0.5, w=7, x='b'), + self.parser.parse_args('0.5 longe b -n 7'.split()), + NS(foo=False, bar=0.5, n=7, o='b'), ) self.assertEqual( - self.parser.parse_args('0.5 lon b -w 7'.split()), - NS(foo=False, bar=0.5, w=7, x='b'), + self.parser.parse_args('0.5 long b -p 7'.split()), + NS(foo=False, bar=0.5, p=7, q='b'), ) self.assertEqual( - self.parser.parse_args('0.5 los b -w 7'.split()), - NS(foo=False, bar=0.5, w=7, x='b'), + self.parser.parse_args('0.5 lon b -p 7'.split()), + NS(foo=False, bar=0.5, p=7, q='b'), + ) + self.assertEqual( + self.parser.parse_args('0.5 los b -r 7'.split()), + NS(foo=False, bar=0.5, r=7, s='b'), ) # check a failure case: 'lo' is ambiguous self.assertArgumentParserError(self.parser.parse_args, - '0.5 lo b -w 7'.split()) + '0.5 lo b -r 7'.split()) def test_parse_args(self): # check some non-failure cases: @@ -1943,80 +1955,85 @@ def test_help(self): self.assertEqual(self.parser.format_usage(), - 'usage: PROG [-h] [--foo] bar {1,2,3,lost,long} ...\n') + 'usage: PROG [-h] [--foo] bar {1,2,3,lost,long,longer} ...\n') self.assertEqual(self.parser.format_help(), textwrap.dedent('''\ - usage: PROG [-h] [--foo] bar {1,2,3,lost,long} ... + usage: PROG [-h] [--foo] bar {1,2,3,lost,long,longer} ... main description positional arguments: - bar bar help - {1,2,3,lost,long} command help + bar bar help + {1,2,3,lost,long,longer} + command help optional arguments: - -h, --help show this help message and exit - --foo foo help + -h, --help show this help message and exit + --foo foo help ''')) def test_help_extra_prefix_chars(self): # Make sure - is still used for help if it is a non-first prefix char parser = self._get_parser(prefix_chars='+:-') self.assertEqual(parser.format_usage(), - 'usage: PROG [-h] [++foo] bar {1,2,3,lost,long} ...\n') + 'usage: PROG [-h] [++foo] bar {1,2,3,lost,long,longer} ...\n') self.assertEqual(parser.format_help(), textwrap.dedent('''\ - usage: PROG [-h] [++foo] bar {1,2,3,lost,long} ... + usage: PROG [-h] [++foo] bar {1,2,3,lost,long,longer} ... main description positional arguments: - bar bar help - {1,2,3,lost,long} command help + bar bar help + {1,2,3,lost,long,longer} + command help optional arguments: - -h, --help show this help message and exit - ++foo foo help + -h, --help show this help message and exit + ++foo foo help ''')) def test_help_alternate_prefix_chars(self): parser = self._get_parser(prefix_chars='+:/') self.assertEqual(parser.format_usage(), - 'usage: PROG [+h] [++foo] bar {1,2,3,lost,long} ...\n') + 'usage: PROG [+h] [++foo] bar {1,2,3,lost,long,longer} ...\n') self.assertEqual(parser.format_help(), textwrap.dedent('''\ - usage: PROG [+h] [++foo] bar {1,2,3,lost,long} ... + usage: PROG [+h] [++foo] bar {1,2,3,lost,long,longer} ... main description positional arguments: - bar bar help - {1,2,3,lost,long} command help + bar bar help + {1,2,3,lost,long,longer} + command help optional arguments: - +h, ++help show this help message and exit - ++foo foo help + +h, ++help show this help message and exit + ++foo foo help ''')) def test_parser_command_help(self): self.assertEqual(self.command_help_parser.format_usage(), - 'usage: PROG [-h] [--foo] bar {1,2,3,lost,long} ...\n') + 'usage: PROG [-h] [--foo] bar {1,2,3,lost,long,longer} ...\n') self.assertEqual(self.command_help_parser.format_help(), textwrap.dedent('''\ - usage: PROG [-h] [--foo] bar {1,2,3,lost,long} ... + usage: PROG [-h] [--foo] bar {1,2,3,lost,long,longer} ... main description positional arguments: - bar bar help - {1,2,3,lost,long} command help - 1 1 help - 2 2 help - 3 3 help - lost lost help - long long help + bar bar help + {1,2,3,lost,long,longer} + command help + 1 1 help + 2 2 help + 3 3 help + lost lost help + long long help + longer longer help optional arguments: - -h, --help show this help message and exit - --foo foo help + -h, --help show this help message and exit + --foo foo help ''')) def test_subparser_title_help(self): @@ -2121,6 +2138,7 @@ 3 3 help lost lost help long long help + longer longer help """)) # ============