Debian Codegraph @

test/units/cli/test_console.py

raw
1 # (c) 2016, Thilo Uttendorfer <[email protected]>
2 #
3 # This file is part of Ansible
4 #
5 # Ansible is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Ansible is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
17
18 from __future__ import annotations
19
20 import unittest
21 from unittest.mock import patch
22
23 from ansible.cli.console import ConsoleCLI
24
25
26 class TestConsoleCLI(unittest.TestCase):
27 def test_parse(self):
28 cli = ConsoleCLI(['ansible test'])
29 cli.parse()
30 self.assertTrue(cli.parser is not None)
31
32 def test_module_args(self):
33 cli = ConsoleCLI(['ansible test'])
34 cli.parse()
35 res = cli.module_args('copy')
36 self.assertTrue(cli.parser is not None)
37 self.assertIn('src', res)
38 self.assertIn('backup', res)
39 self.assertIsInstance(res, list)
40
41 @patch('ansible.utils.display.Display.display')
42 def test_helpdefault(self, mock_display):
43 cli = ConsoleCLI(['ansible test'])
44 cli.parse()
45 cli.modules = set(['copy'])
46 cli.helpdefault('copy')
47 self.assertTrue(cli.parser is not None)
48 self.assertTrue(len(mock_display.call_args_list) > 0,
49 "display.display should have been called but was not")