1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
5 # http://www.apache.org/licenses/LICENSE-2.0
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
13 from cliff import command
16 class TestCommand(command.Command):
17 """Description of command.
20 def take_action(self, parsed_args):
24 class TestCommandNoDocstring(command.Command):
26 def take_action(self, parsed_args):
30 def test_get_description_docstring():
31 cmd = TestCommand(None, None)
32 desc = cmd.get_description()
33 assert desc == "Description of command.\n "
36 def test_get_description_attribute():
37 cmd = TestCommand(None, None)
38 # Artificially inject a value for _description to verify that it
39 # overrides the docstring.
40 cmd._description = 'this is not the default'
41 desc = cmd.get_description()
42 assert desc == 'this is not the default'
45 def test_get_description_default():
46 cmd = TestCommandNoDocstring(None, None)
47 desc = cmd.get_description()
51 def test_get_parser():
52 cmd = TestCommand(None, None)
53 parser = cmd.get_parser('NAME')
54 assert parser.prog == 'NAME'
58 cmd = TestCommand(None, None, cmd_name='object action')
59 assert cmd.cmd_name == 'object action'
62 def test_run_return():
63 cmd = TestCommand(None, None, cmd_name='object action')
64 assert cmd.run(None) == 42