]> granicus.if.org Git - python/commitdiff
Issue #9026: Fix order of argparse sub-commands in help messages. (Merged from 3.2.)
authorSteven Bethard <steven.bethard@gmail.com>
Sun, 27 Mar 2011 12:04:03 +0000 (14:04 +0200)
committerSteven Bethard <steven.bethard@gmail.com>
Sun, 27 Mar 2011 12:04:03 +0000 (14:04 +0200)
1  2 
Lib/argparse.py
Lib/test/test_argparse.py
Misc/NEWS

diff --cc Lib/argparse.py
Simple merge
index 0fd554c6f3df78e626d220e738395bac569f4bd4,e1876534c3273a2b64386e3607477528d728ddde..6ca1019c9a4f8229464d11e6e64562e18d311520
@@@ -3940,37 -3946,77 +3946,108 @@@ class TestHelpVersionAction(HelpTestCas
          '''
      version = ''
  
+ class TestHelpSubparsersOrdering(HelpTestCase):
+     """Test ordering of subcommands in help matches the code"""
+     parser_signature = Sig(prog='PROG',
+                            description='display some subcommands',
+                            version='0.1')
+     subparsers_signatures = [Sig(name=name)
+                              for name in ('a', 'b', 'c', 'd', 'e')]
+     usage = '''\
+         usage: PROG [-h] [-v] {a,b,c,d,e} ...
+         '''
+     help = usage + '''\
+         display some subcommands
+         positional arguments:
+           {a,b,c,d,e}
+         optional arguments:
+           -h, --help     show this help message and exit
+           -v, --version  show program's version number and exit
+         '''
+     version = '''\
+         0.1
+         '''
+ class TestHelpSubparsersWithHelpOrdering(HelpTestCase):
+     """Test ordering of subcommands in help matches the code"""
+     parser_signature = Sig(prog='PROG',
+                            description='display some subcommands',
+                            version='0.1')
+     subcommand_data = (('a', 'a subcommand help'),
+                        ('b', 'b subcommand help'),
+                        ('c', 'c subcommand help'),
+                        ('d', 'd subcommand help'),
+                        ('e', 'e subcommand help'),
+                        )
+     subparsers_signatures = [Sig(name=name, help=help)
+                              for name, help in subcommand_data]
+     usage = '''\
+         usage: PROG [-h] [-v] {a,b,c,d,e} ...
+         '''
+     help = usage + '''\
+         display some subcommands
+         positional arguments:
+           {a,b,c,d,e}
+             a            a subcommand help
+             b            b subcommand help
+             c            c subcommand help
+             d            d subcommand help
+             e            e subcommand help
+         optional arguments:
+           -h, --help     show this help message and exit
+           -v, --version  show program's version number and exit
+         '''
+     version = '''\
+         0.1
+         '''
 +
 +class TestHelpMetavarTypeFormatter(HelpTestCase):
 +    """"""
 +
 +    def custom_type(string):
 +        return string
 +
 +    parser_signature = Sig(prog='PROG', description='description',
 +                           formatter_class=argparse.MetavarTypeHelpFormatter)
 +    argument_signatures = [Sig('a', type=int),
 +                           Sig('-b', type=custom_type),
 +                           Sig('-c', type=float, metavar='SOME FLOAT')]
 +    argument_group_signatures = []
 +    usage = '''\
 +        usage: PROG [-h] [-b custom_type] [-c SOME FLOAT] int
 +        '''
 +    help = usage + '''\
 +
 +        description
 +
 +        positional arguments:
 +          int
 +
 +        optional arguments:
 +          -h, --help      show this help message and exit
 +          -b custom_type
 +          -c SOME FLOAT
 +        '''
 +    version = ''
 +
 +
  # =====================================
  # Optional/Positional constructor tests
  # =====================================
diff --cc Misc/NEWS
Simple merge