ansible/test/units/executor/module_common/test_modify_module.py
Matt Davis 4d3a6123d5
Python interpreter discovery ()
* Python interpreter discovery

* No longer blindly default to only `/usr/bin/python`
* `ansible_python_interpreter` defaults to `auto_legacy`, which will discover the platform Python interpreter on some platforms (but still favor `/usr/bin/python` if present for backward compatibility). Use `auto` to always use the discovered interpreter, append `_silent` to either value to suppress warnings.
* includes new doc utility method `get_versioned_doclink` to generate a major.minor versioned doclink against docs.ansible.com (or some other config-overridden URL)

* docs revisions for python interpreter discovery

(cherry picked from commit 5b53c0012ab7212304c28fdd24cb33fd8ff755c2)

* verify output on some distros, cleanup
2019-02-27 23:52:02 -08:00

43 lines
1.4 KiB
Python

# Copyright (c) 2018 Matt Martz <matt@sivel.net>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import pytest
from ansible.executor.module_common import modify_module
from ansible.module_utils.six import PY2
from test_module_common import templar
FAKE_OLD_MODULE = b'''#!/usr/bin/python
import sys
print('{"result": "%s"}' % sys.executable)
'''
@pytest.fixture
def fake_old_module_open(mocker):
m = mocker.mock_open(read_data=FAKE_OLD_MODULE)
if PY2:
mocker.patch('__builtin__.open', m)
else:
mocker.patch('builtins.open', m)
# this test no longer makes sense, since a Python module will always either have interpreter discovery run or
# an explicit interpreter passed (so we'll never default to the module shebang)
# def test_shebang(fake_old_module_open, templar):
# (data, style, shebang) = modify_module('fake_module', 'fake_path', {}, templar)
# assert shebang == '#!/usr/bin/python'
def test_shebang_task_vars(fake_old_module_open, templar):
task_vars = {
'ansible_python_interpreter': '/usr/bin/python3'
}
(data, style, shebang) = modify_module('fake_module', 'fake_path', {}, templar, task_vars=task_vars)
assert shebang == '#!/usr/bin/python3'