mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Start of tests for modify_module, specifically to ensure proper shebang replacement on old style modules (#36602)
This commit is contained in:
parent
4a8b4bb8a8
commit
a7062b7587
1 changed files with 42 additions and 0 deletions
42
test/units/executor/module_common/test_modify_module.py
Normal file
42
test/units/executor/module_common/test_modify_module.py
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
|
||||||
|
def test_shebang(fake_old_module_open):
|
||||||
|
(data, style, shebang) = modify_module('fake_module', 'fake_path', {})
|
||||||
|
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', {}, task_vars=task_vars, templar=templar)
|
||||||
|
assert shebang == '#!/usr/bin/python3'
|
Loading…
Reference in a new issue