ef6b051ccc39d16afea6311dad553f5d9a08ee21
[sdc/sdc-distribution-client.git] /
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
4 #
5 #       http://www.apache.org/licenses/LICENSE-2.0
6 #
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
11 #  under the License.
12
13 from cliff import command
14
15
16 class TestCommand(command.Command):
17     """Description of command.
18     """
19
20     def take_action(self, parsed_args):
21         return 42
22
23
24 class TestCommandNoDocstring(command.Command):
25
26     def take_action(self, parsed_args):
27         return 42
28
29
30 def test_get_description_docstring():
31     cmd = TestCommand(None, None)
32     desc = cmd.get_description()
33     assert desc == "Description of command.\n    "
34
35
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'
43
44
45 def test_get_description_default():
46     cmd = TestCommandNoDocstring(None, None)
47     desc = cmd.get_description()
48     assert desc == ''
49
50
51 def test_get_parser():
52     cmd = TestCommand(None, None)
53     parser = cmd.get_parser('NAME')
54     assert parser.prog == 'NAME'
55
56
57 def test_get_name():
58     cmd = TestCommand(None, None, cmd_name='object action')
59     assert cmd.cmd_name == 'object action'
60
61
62 def test_run_return():
63     cmd = TestCommand(None, None, cmd_name='object action')
64     assert cmd.run(None) == 42