1# Copyright (c) 2018 Matt Martz <matt@sivel.net> 2# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3# -*- coding: utf-8 -*- 4 5from __future__ import (absolute_import, division, print_function) 6__metaclass__ = type 7 8import pytest 9 10from ansible.executor.module_common import modify_module 11from ansible.module_utils.six import PY2 12 13from test_module_common import templar 14 15 16FAKE_OLD_MODULE = b'''#!/usr/bin/python 17import sys 18print('{"result": "%s"}' % sys.executable) 19''' 20 21 22@pytest.fixture 23def fake_old_module_open(mocker): 24 m = mocker.mock_open(read_data=FAKE_OLD_MODULE) 25 if PY2: 26 mocker.patch('__builtin__.open', m) 27 else: 28 mocker.patch('builtins.open', m) 29 30# this test no longer makes sense, since a Python module will always either have interpreter discovery run or 31# an explicit interpreter passed (so we'll never default to the module shebang) 32# def test_shebang(fake_old_module_open, templar): 33# (data, style, shebang) = modify_module('fake_module', 'fake_path', {}, templar) 34# assert shebang == '#!/usr/bin/python' 35 36 37def test_shebang_task_vars(fake_old_module_open, templar): 38 task_vars = { 39 'ansible_python_interpreter': '/usr/bin/python3' 40 } 41 42 (data, style, shebang) = modify_module('fake_module', 'fake_path', {}, templar, task_vars=task_vars) 43 assert shebang == '#!/usr/bin/python3' 44