Merge "Fix subparsers add_parser() regression"

This commit is contained in:
Jenkins 2013-09-26 09:05:00 +00:00 committed by Gerrit Code Review
commit eae8b3108d
2 changed files with 18 additions and 2 deletions

View File

@ -1469,8 +1469,8 @@ class _CachedArgumentParser(argparse.ArgumentParser):
order.
"""
def __init__(self, prog=None, usage=None):
super(_CachedArgumentParser, self).__init__(prog, usage)
def __init__(self, prog=None, usage=None, **kwargs):
super(_CachedArgumentParser, self).__init__(prog, usage, **kwargs)
self._args_cache = {}
def add_parser_argument(self, container, *args, **kwargs):

View File

@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import argparse
import os
import shutil
import sys
@ -2627,6 +2628,21 @@ class SubCommandTestCase(BaseTestCase):
self.assertEqual(self.conf.cmd.name, 'a')
self.assertEqual(self.conf.cmd.bar, 10)
def test_sub_command_with_parent(self):
def add_parsers(subparsers):
parent = argparse.ArgumentParser(add_help=False)
parent.add_argument('bar', type=int)
subparsers.add_parser('a', parents=[parent])
self.conf.register_cli_opt(
cfg.SubCommandOpt('cmd', handler=add_parsers))
self.assertTrue(hasattr(self.conf, 'cmd'))
self.conf(['a', '10'])
self.assertTrue(hasattr(self.conf.cmd, 'name'))
self.assertTrue(hasattr(self.conf.cmd, 'bar'))
self.assertEqual(self.conf.cmd.name, 'a')
self.assertEqual(self.conf.cmd.bar, 10)
def test_sub_command_with_dest(self):
def add_parsers(subparsers):
subparsers.add_parser('a')