Commit 901e9500 authored by Steven Bethard's avatar Steven Bethard

Merged revisions 86092 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r86092 | steven.bethard | 2010-11-01 17:29:26 +0100 (Mon, 01 Nov 2010) | 1 line

  Fix for issue 9355 where with multiple mutually exclusive arguments, some brackets were being lost in the usage messages
........
parent e2bb70f0
......@@ -392,10 +392,16 @@ class HelpFormatter(object):
for action in group._group_actions:
group_actions.add(action)
if not group.required:
inserts[start] = '['
if start in inserts:
inserts[start] += ' ['
else:
inserts[start] = '['
inserts[end] = ']'
else:
inserts[start] = '('
if start in inserts:
inserts[start] += ' ('
else:
inserts[start] = '('
inserts[end] = ')'
for i in range(start + 1, end):
inserts[i] = '|'
......
......@@ -2174,6 +2174,25 @@ class TestMutuallyExclusiveGroupErrors(TestCase):
raises(ValueError, add_argument, 'bar', nargs=1)
raises(ValueError, add_argument, 'bar', nargs=argparse.PARSER)
def test_help(self):
parser = ErrorRaisingArgumentParser(prog='PROG')
group1 = parser.add_mutually_exclusive_group()
group1.add_argument('--foo', action='store_true')
group1.add_argument('--bar', action='store_false')
group2 = parser.add_mutually_exclusive_group()
group2.add_argument('--soup', action='store_true')
group2.add_argument('--nuts', action='store_false')
expected = '''\
usage: PROG [-h] [--foo | --bar] [--soup | --nuts]
optional arguments:
-h, --help show this help message and exit
--foo
--bar
--soup
--nuts
'''
self.assertEqual(parser.format_help(), textwrap.dedent(expected))
class MEMixin(object):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment