From 5aada5194e4a101c1daf38f67a49370597700969 Mon Sep 17 00:00:00 2001 From: ForestLee Date: Sun, 12 Mar 2017 09:47:29 +0800 Subject: [PATCH] delete bash_completion in subcommand There are two "completion" in the subcommand table: bash-completion and bash_completion. but "bash_completion" is not in help information and it is repeated with "bash-completion", so delete it. Change-Id: I0c2fb8b77b737c2ffc05dd4bb641125e88a4fde4 Closes-Bug: #1670123 --- senlinclient/shell.py | 11 +---------- senlinclient/tests/unit/test_shell.py | 21 +-------------------- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/senlinclient/shell.py b/senlinclient/shell.py index 9233868..0e9a067 100644 --- a/senlinclient/shell.py +++ b/senlinclient/shell.py @@ -89,7 +89,7 @@ class SenlinShell(object): commands = set() options = set() for sc_str, sc in self.subcommands.items(): - if sc_str == 'bash_completion' or sc_str == 'bash-completion': + if sc_str == 'bash-completion': continue commands.add(sc_str) @@ -110,14 +110,6 @@ class SenlinShell(object): 'Without the key, profiling will not be triggered ' 'even if osprofiler is enabled on server side.')) - def _add_bash_completion_subparser(self, subparsers): - subparser = subparsers.add_parser('bash_completion', - add_help=False, - formatter_class=HelpFormatter) - - subparser.set_defaults(func=self.do_bash_completion) - self.subcommands['bash_completion'] = subparser - def get_subcommand_parser(self, base_parser, version): parser = base_parser @@ -126,7 +118,6 @@ class SenlinShell(object): submodule = utils.import_versioned_module(version, 'shell') self._find_actions(subparsers, submodule) self._find_actions(subparsers, self) - self._add_bash_completion_subparser(subparsers) return parser diff --git a/senlinclient/tests/unit/test_shell.py b/senlinclient/tests/unit/test_shell.py index cd35257..3f103a5 100644 --- a/senlinclient/tests/unit/test_shell.py +++ b/senlinclient/tests/unit/test_shell.py @@ -176,7 +176,6 @@ class ShellTest(testtools.TestCase): 'command-foo': sc1, 'command-bar': sc2, 'bash-completion': None, - 'bash_completion': None, } output = self.SHELL(sh.do_bash_completion, None) @@ -195,26 +194,9 @@ class ShellTest(testtools.TestCase): self.assertEqual(0, parser.add_argument.call_count) - def test_add_bash_completion_subparser(self): - sh = shell.SenlinShell() - sh.subcommands = {} - x_subparser = mock.Mock() - x_subparsers = mock.Mock() - x_subparsers.add_parser.return_value = x_subparser - - sh._add_bash_completion_subparser(x_subparsers) - - x_subparsers.add_parser.assert_called_once_with( - 'bash_completion', add_help=False, - formatter_class=shell.HelpFormatter) - self.assertEqual({'bash_completion': x_subparser}, sh.subcommands) - x_subparser.set_defaults.assert_called_once_with( - func=sh.do_bash_completion) - @mock.patch.object(utils, 'import_versioned_module') @mock.patch.object(shell.SenlinShell, '_find_actions') - @mock.patch.object(shell.SenlinShell, '_add_bash_completion_subparser') - def test_get_subcommand_parser(self, x_add, x_find, x_import): + def test_get_subcommand_parser(self, x_find, x_import): x_base = mock.Mock() x_module = mock.Mock() x_import.return_value = x_module @@ -233,7 +215,6 @@ class ShellTest(testtools.TestCase): ] x_find.assert_has_calls(find_calls) - x_add.assert_called_once_with(x_subparsers) @mock.patch.object(argparse.ArgumentParser, 'print_help') def test_do_help(self, mock_print):