diff options
author | Mike Fedosin <mfedosin@mirantis.com> | 2014-11-18 05:14:32 +0300 |
---|---|---|
committer | Mike Fedosin <mfedosin@mirantis.com> | 2014-12-04 20:16:10 +0300 |
commit | e447675ef8a24665bfe3e5c22389f1c73b79923f (patch) | |
tree | 77d221cddcdbd959029e45fe0a88b35743b8a83a /tests/test_cfg.py | |
parent | 32a0983944b99fecad28ed037702806622f025c3 (diff) | |
download | oslo-config-e447675ef8a24665bfe3e5c22389f1c73b79923f.tar.gz |
Fix wrong order of positional args in cli
Positional arguments were incorrectly parsed because instead of
original order there was an alphabetical.
This patch brings a positional field in Opt class and then sorts
all arguments by position-name.
Change-Id: Ia22654442b895c3f62834428f0ec6c3e8af22ebb
Closes-Bug: 1392428
Diffstat (limited to 'tests/test_cfg.py')
-rw-r--r-- | tests/test_cfg.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/test_cfg.py b/tests/test_cfg.py index 01823b1..0943348 100644 --- a/tests/test_cfg.py +++ b/tests/test_cfg.py @@ -622,6 +622,62 @@ class PositionalTestCase(BaseTestCase): cfg.StrOpt('foo', required=True, positional=True)) self.assertRaises(cfg.RequiredOptError, self.conf, []) + def test_positional_opts_order(self): + self.conf.register_cli_opts(( + cfg.StrOpt('command', positional=True), + cfg.StrOpt('arg1', positional=True), + cfg.StrOpt('arg2', positional=True)) + ) + + self.conf(['command', 'arg1', 'arg2']) + + self.assertEqual('command', self.conf.command) + self.assertEqual('arg1', self.conf.arg1) + self.assertEqual('arg2', self.conf.arg2) + + def test_positional_opt_order(self): + self.conf.register_cli_opt( + cfg.StrOpt('command', positional=True)) + self.conf.register_cli_opt( + cfg.StrOpt('arg1', positional=True)) + self.conf.register_cli_opt( + cfg.StrOpt('arg2', positional=True)) + + self.conf(['command', 'arg1', 'arg2']) + + self.assertEqual('command', self.conf.command) + self.assertEqual('arg1', self.conf.arg1) + self.assertEqual('arg2', self.conf.arg2) + + def test_positional_opt_unregister(self): + command = cfg.StrOpt('command', positional=True) + arg1 = cfg.StrOpt('arg1', positional=True) + arg2 = cfg.StrOpt('arg2', positional=True) + self.conf.register_cli_opt(command) + self.conf.register_cli_opt(arg1) + self.conf.register_cli_opt(arg2) + + self.conf(['command', 'arg1', 'arg2']) + + self.assertEqual('command', self.conf.command) + self.assertEqual('arg1', self.conf.arg1) + self.assertEqual('arg2', self.conf.arg2) + + self.conf.reset() + + self.conf.unregister_opt(arg1) + self.conf.unregister_opt(arg2) + + arg0 = cfg.StrOpt('arg0', positional=True) + self.conf.register_cli_opt(arg0) + self.conf.register_cli_opt(arg1) + + self.conf(['command', 'arg0', 'arg1']) + + self.assertEqual('command', self.conf.command) + self.assertEqual('arg0', self.conf.arg0) + self.assertEqual('arg1', self.conf.arg1) + class ConfigFileOptsTestCase(BaseTestCase): |