Debian Codegraph @

test/units/cli/arguments/test_option_helpers.py

raw
1 # -*- coding: utf-8 -*-
2 # Copyright: (c) 2018, Ansible Project
3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4
5 from __future__ import annotations
6
7 import sys
8
9 import pytest
10 import pytest_mock
11
12 from ansible import constants as C
13 from ansible.cli.arguments import option_helpers as opt_help
14 from ansible.cli.arguments.option_helpers import version
15 from ansible import __path__ as ansible_path
16 from ansible.release import __version__ as ansible_version
17
18 cpath = C.DEFAULT_MODULE_PATH
19
20 FAKE_PROG = u'ansible-cli-test'
21 VERSION_OUTPUT = opt_help.version(prog=FAKE_PROG)
22
23
24 @pytest.mark.parametrize(
25 'must_have', [
26 FAKE_PROG + u' [core %s]' % ansible_version,
27 u'config file = %s' % C.CONFIG_FILE,
28 u'configured module search path = %s' % cpath,
29 u'ansible python module location = %s' % ':'.join(ansible_path),
30 u'ansible collection location = %s' % ':'.join(C.COLLECTIONS_PATHS),
31 u'executable location = ',
32 u'python version = %s' % ''.join(sys.version.splitlines()),
33 ]
34 )
35 def test_option_helper_version(must_have):
36 assert must_have in VERSION_OUTPUT
37
38
39 def test_libyaml_version_known(mocker: pytest_mock.MockerFixture) -> None:
40 import yaml._yaml
41 mocker.patch.object(yaml._yaml, 'get_version_string', return_value='1.2.3')
42 result = version()
43 assert 'with libyaml v1.2.3' in result
44
45
46 def test_libyaml_version_unknown(mocker: pytest_mock.MockerFixture) -> None:
47 import yaml._yaml
48 mocker.patch.object(yaml._yaml, 'get_version_string', side_effect=NotImplementedError)
49 result = version()
50 assert 'with libyaml, version unknown' in result