mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 19:31:26 -07:00
Fix shebang. shebang and interpreter path weren't being templated (#33698)
* Fix shebang. shebang and interpreter path weren't being templated Fixes #18665 Fixes #33696
This commit is contained in:
parent
c8a5e689e3
commit
b455901904
3 changed files with 34 additions and 22 deletions
|
@ -93,26 +93,35 @@ class TestSlurp(object):
|
|||
assert amc._slurp('some_file') == '#!/usr/bin/python\ndef test(args):\nprint("hi")\n'
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def templar():
|
||||
class FakeTemplar(object):
|
||||
def template(self, template_string, *args, **kwargs):
|
||||
return template_string
|
||||
|
||||
return FakeTemplar()
|
||||
|
||||
|
||||
class TestGetShebang(object):
|
||||
"""Note: We may want to change the API of this function in the future. It isn't a great API"""
|
||||
def test_no_interpreter_set(self):
|
||||
assert amc._get_shebang(u'/usr/bin/python', {}) == (None, u'/usr/bin/python')
|
||||
def test_no_interpreter_set(self, templar):
|
||||
assert amc._get_shebang(u'/usr/bin/python', {}, templar) == (None, u'/usr/bin/python')
|
||||
|
||||
def test_non_python_interpreter(self):
|
||||
assert amc._get_shebang(u'/usr/bin/ruby', {}) == (None, u'/usr/bin/ruby')
|
||||
def test_non_python_interpreter(self, templar):
|
||||
assert amc._get_shebang(u'/usr/bin/ruby', {}, templar) == (None, u'/usr/bin/ruby')
|
||||
|
||||
def test_interpreter_set_in_task_vars(self):
|
||||
assert amc._get_shebang(u'/usr/bin/python', {u'ansible_python_interpreter': u'/usr/bin/pypy'}) == \
|
||||
def test_interpreter_set_in_task_vars(self, templar):
|
||||
assert amc._get_shebang(u'/usr/bin/python', {u'ansible_python_interpreter': u'/usr/bin/pypy'}, templar) == \
|
||||
(u'#!/usr/bin/pypy', u'/usr/bin/pypy')
|
||||
|
||||
def test_non_python_interpreter_in_task_vars(self):
|
||||
assert amc._get_shebang(u'/usr/bin/ruby', {u'ansible_ruby_interpreter': u'/usr/local/bin/ruby'}) == \
|
||||
def test_non_python_interpreter_in_task_vars(self, templar):
|
||||
assert amc._get_shebang(u'/usr/bin/ruby', {u'ansible_ruby_interpreter': u'/usr/local/bin/ruby'}, templar) == \
|
||||
(u'#!/usr/local/bin/ruby', u'/usr/local/bin/ruby')
|
||||
|
||||
def test_with_args(self):
|
||||
assert amc._get_shebang(u'/usr/bin/python', {u'ansible_python_interpreter': u'/usr/bin/python3'}, args=('-tt', '-OO')) == \
|
||||
def test_with_args(self, templar):
|
||||
assert amc._get_shebang(u'/usr/bin/python', {u'ansible_python_interpreter': u'/usr/bin/python3'}, templar, args=('-tt', '-OO')) == \
|
||||
(u'#!/usr/bin/python3 -tt -OO', u'/usr/bin/python3')
|
||||
|
||||
def test_python_via_env(self):
|
||||
assert amc._get_shebang(u'/usr/bin/python', {u'ansible_python_interpreter': u'/usr/bin/env python'}) == \
|
||||
def test_python_via_env(self, templar):
|
||||
assert amc._get_shebang(u'/usr/bin/python', {u'ansible_python_interpreter': u'/usr/bin/env python'}, templar) == \
|
||||
(u'#!/usr/bin/env python', u'/usr/bin/env python')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue