Pick a better python shebang for hook executable

This commit is contained in:
Anthony Sottile 2018-12-25 12:11:02 -08:00
parent 748c2ad273
commit de942894ff
2 changed files with 33 additions and 0 deletions

View file

@ -17,7 +17,9 @@ from pre_commit.commands.install_uninstall import install
from pre_commit.commands.install_uninstall import install_hooks
from pre_commit.commands.install_uninstall import is_our_script
from pre_commit.commands.install_uninstall import PRIOR_HASHES
from pre_commit.commands.install_uninstall import shebang
from pre_commit.commands.install_uninstall import uninstall
from pre_commit.languages import python
from pre_commit.runner import Runner
from pre_commit.util import cmd_output
from pre_commit.util import make_executable
@ -45,6 +47,24 @@ def test_is_previous_pre_commit(tmpdir):
assert is_our_script(f.strpath)
def test_shebang_windows():
with mock.patch.object(sys, 'platform', 'win32'):
assert shebang() == '#!/usr/bin/env python'
def test_shebang_otherwise():
with mock.patch.object(sys, 'platform', 'posix'):
assert 'default' not in shebang()
def test_shebang_returns_default():
with mock.patch.object(sys, 'platform', 'posix'):
with mock.patch.object(
python, 'get_default_version', return_value='default',
):
assert shebang() == '#!/usr/bin/env python'
def test_install_pre_commit(tempdir_factory, store):
path = git_dir(tempdir_factory)
runner = Runner(path, C.CONFIG_FILE)