mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-25 02:19:10 -07:00
Restore ansible --version output (#55728)
* Add custom action class for version info * Use args from CLI as prog for ArgumentParser object * Make prog a required parameter of create_base_parser() and update all uses to pass in the newly required parameter. * Add unit test for checking ansible --version * Update other related unit tests
This commit is contained in:
parent
c195645575
commit
b3ce3fc5eb
7 changed files with 47 additions and 13 deletions
|
@ -5,6 +5,7 @@ from __future__ import (absolute_import, division, print_function)
|
|||
__metaclass__ = type
|
||||
|
||||
import pytest
|
||||
import re
|
||||
|
||||
from ansible import context
|
||||
from ansible.cli.adhoc import AdHocCLI, display
|
||||
|
@ -13,8 +14,11 @@ from ansible.errors import AnsibleOptionsError
|
|||
|
||||
def test_parse():
|
||||
""" Test adhoc parse"""
|
||||
adhoc_cli = AdHocCLI([])
|
||||
with pytest.raises(SystemExit) as exec_info:
|
||||
with pytest.raises(ValueError, match='A non-empty list for args is required'):
|
||||
adhoc_cli = AdHocCLI([])
|
||||
|
||||
adhoc_cli = AdHocCLI(['ansibletest'])
|
||||
with pytest.raises(SystemExit):
|
||||
adhoc_cli.parse()
|
||||
|
||||
|
||||
|
@ -87,3 +91,23 @@ def test_run_no_extra_vars():
|
|||
with pytest.raises(SystemExit) as exec_info:
|
||||
adhoc_cli.parse()
|
||||
assert exec_info.value.code == 2
|
||||
|
||||
|
||||
def test_ansible_version(capsys, mocker):
|
||||
adhoc_cli = AdHocCLI(args=['/bin/ansible', '--version'])
|
||||
with pytest.raises(SystemExit):
|
||||
adhoc_cli.run()
|
||||
version = capsys.readouterr()
|
||||
try:
|
||||
version_lines = version.out.splitlines()
|
||||
except AttributeError:
|
||||
# Python 2.6 does return a named tuple, so get the first item
|
||||
version_lines = version[0].splitlines()
|
||||
|
||||
assert len(version_lines) == 6, 'Incorrect number of lines in "ansible --version" output'
|
||||
assert re.match('ansible [0-9.a-z]+$', version_lines[0]), 'Incorrect ansible version line in "ansible --version" output'
|
||||
assert re.match(' config file = .*$', version_lines[1]), 'Incorrect config file line in "ansible --version" output'
|
||||
assert re.match(' configured module search path = .*$', version_lines[2]), 'Incorrect module search path in "ansible --version" output'
|
||||
assert re.match(' ansible python module location = .*$', version_lines[3]), 'Incorrect python module location in "ansible --version" output'
|
||||
assert re.match(' executable location = .*$', version_lines[4]), 'Incorrect executable locaction in "ansible --version" output'
|
||||
assert re.match(' python version = .*$', version_lines[5]), 'Incorrect python version in "ansible --version" output'
|
||||
|
|
|
@ -27,12 +27,12 @@ from ansible.cli.console import ConsoleCLI
|
|||
|
||||
class TestConsoleCLI(unittest.TestCase):
|
||||
def test_parse(self):
|
||||
cli = ConsoleCLI([])
|
||||
cli = ConsoleCLI(['ansible test'])
|
||||
cli.parse()
|
||||
self.assertTrue(cli.parser is not None)
|
||||
|
||||
def test_module_args(self):
|
||||
cli = ConsoleCLI([])
|
||||
cli = ConsoleCLI(['ansible test'])
|
||||
cli.parse()
|
||||
res = cli.module_args('copy')
|
||||
self.assertTrue(cli.parser is not None)
|
||||
|
@ -42,7 +42,7 @@ class TestConsoleCLI(unittest.TestCase):
|
|||
|
||||
@patch('ansible.utils.display.Display.display')
|
||||
def test_helpdefault(self, mock_display):
|
||||
cli = ConsoleCLI([])
|
||||
cli = ConsoleCLI(['ansible test'])
|
||||
cli.parse()
|
||||
cli.modules = set(['copy'])
|
||||
cli.helpdefault('copy')
|
||||
|
|
|
@ -40,7 +40,7 @@ class TestVaultCli(unittest.TestCase):
|
|||
self.tty_patcher.stop()
|
||||
|
||||
def test_parse_empty(self):
|
||||
cli = VaultCLI([])
|
||||
cli = VaultCLI(['vaultcli'])
|
||||
self.assertRaises(SystemExit,
|
||||
cli.parse)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue