diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-11-16 03:50:26 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-11-16 03:50:26 +0000 |
| commit | ea0252529dc37de115cea2e2f9e0aaac3f148efe (patch) | |
| tree | 2318d34b2ada168c0f16cb75f1061a16e978c68e | |
| parent | 08582516b3eec3327d2f12def4b35edf6a3c0b26 (diff) | |
| parent | 768a147ac5e993df3eda3558542a3fe81b8a3d11 (diff) | |
| download | oslo-ea0252529dc37de115cea2e2f9e0aaac3f148efe.tar.gz oslo-ea0252529dc37de115cea2e2f9e0aaac3f148efe.tar.xz oslo-ea0252529dc37de115cea2e2f9e0aaac3f148efe.zip | |
Merge "Use stock argparse --usage behaviour"
| -rw-r--r-- | openstack/common/cfg.py | 22 | ||||
| -rw-r--r-- | tests/unit/test_cfg.py | 6 |
2 files changed, 3 insertions, 25 deletions
diff --git a/openstack/common/cfg.py b/openstack/common/cfg.py index d234608..f4757bc 100644 --- a/openstack/common/cfg.py +++ b/openstack/common/cfg.py @@ -930,10 +930,6 @@ class ConfigCliParser(argparse.ArgumentParser): def __init__(self, prog=None, usage=None, version=None, *args, **kwargs): super(ConfigCliParser, self).__init__(prog=prog, usage=usage, *args, **kwargs) - # to eliminate error: - # ValueError: unsupported format character 'p' (0x70) at index 1 - if usage is not None: - self.usage = usage.replace("%prog", self.prog) self.add_argument('--version', action='version', version=version) self._optionals.title = 'Options' @@ -961,24 +957,6 @@ class ConfigCliParser(argparse.ArgumentParser): return opts, args - def print_usage(self, file=None): - ''' - overriding original print_usage method, only for - compatibility with optparse and happiness of unittest - ''' - print >>file, "Usage: " + self.usage - - def print_help(self, file=None): - ''' - overriding original print_usage method, only for - compatibility with optparse and happiness of unittest - unittest: HelpTestCase:test_print_help - ''' - msg = self.format_help() - if 0 == msg.find("usage:"): - msg = msg.replace("usage:", "Usage:") - print >>file, msg - class ConfigOpts(collections.Mapping): diff --git a/tests/unit/test_cfg.py b/tests/unit/test_cfg.py index d4559d0..84ab73e 100644 --- a/tests/unit/test_cfg.py +++ b/tests/unit/test_cfg.py @@ -81,7 +81,7 @@ class BaseTestCase(unittest.TestCase): args=args, prog='test', version='1.0', - usage='%prog FOO BAR', + usage='%(prog)s FOO BAR', default_config_files=[]) def setUp(self): @@ -122,7 +122,7 @@ class UsageTestCase(BaseTestCase): f = StringIO.StringIO() self.conf([]) self.conf.print_usage(file=f) - self.assertTrue('Usage: test FOO BAR' in f.getvalue()) + self.assertTrue('usage: test FOO BAR' in f.getvalue()) self.assertTrue('Options:' not in f.getvalue()) @@ -132,7 +132,7 @@ class HelpTestCase(BaseTestCase): f = StringIO.StringIO() self.conf([]) self.conf.print_help(file=f) - self.assertTrue('Usage: test FOO BAR' in f.getvalue()) + self.assertTrue('usage: test FOO BAR' in f.getvalue()) self.assertTrue('Options:' in f.getvalue()) self.assertTrue('-h, --help' in f.getvalue()) |
