Skip to content

Commit

Permalink
Merge "Fix subparsers add_parser() regression"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Sep 26, 2013
2 parents 3d59667 + bf70519 commit eae8b31
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions oslo/config/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
16 changes: 16 additions & 0 deletions tests/test_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.

import argparse
import os
import shutil
import sys
Expand Down Expand Up @@ -2627,6 +2628,21 @@ def add_parsers(subparsers):
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')
Expand Down

0 comments on commit eae8b31

Please sign in to comment.