|
1 | 1 | import os.path |
2 | 2 | import re |
3 | | -import sys |
4 | | -from unittest import mock |
5 | 3 |
|
6 | 4 | import re_assert |
7 | 5 |
|
8 | 6 | import pre_commit.constants as C |
9 | 7 | from pre_commit import git |
10 | | -from pre_commit.commands import install_uninstall |
11 | 8 | from pre_commit.commands.install_uninstall import CURRENT_HASH |
12 | 9 | from pre_commit.commands.install_uninstall import install |
13 | 10 | from pre_commit.commands.install_uninstall import install_hooks |
14 | 11 | from pre_commit.commands.install_uninstall import is_our_script |
15 | 12 | from pre_commit.commands.install_uninstall import PRIOR_HASHES |
16 | | -from pre_commit.commands.install_uninstall import shebang |
17 | 13 | from pre_commit.commands.install_uninstall import uninstall |
18 | 14 | from pre_commit.parse_shebang import find_executable |
19 | 15 | from pre_commit.util import cmd_output |
@@ -43,43 +39,6 @@ def test_is_previous_pre_commit(tmpdir): |
43 | 39 | assert is_our_script(f.strpath) |
44 | 40 |
|
45 | 41 |
|
46 | | -def patch_platform(platform): |
47 | | - return mock.patch.object(sys, 'platform', platform) |
48 | | - |
49 | | - |
50 | | -def patch_lookup_path(path): |
51 | | - return mock.patch.object(install_uninstall, 'POSIX_SEARCH_PATH', path) |
52 | | - |
53 | | - |
54 | | -def patch_sys_exe(exe): |
55 | | - return mock.patch.object(install_uninstall, 'SYS_EXE', exe) |
56 | | - |
57 | | - |
58 | | -def test_shebang_windows(): |
59 | | - with patch_platform('win32'), patch_sys_exe('python'): |
60 | | - assert shebang() == '#!/usr/bin/env python' |
61 | | - |
62 | | - |
63 | | -def test_shebang_windows_drop_ext(): |
64 | | - with patch_platform('win32'), patch_sys_exe('python.exe'): |
65 | | - assert shebang() == '#!/usr/bin/env python' |
66 | | - |
67 | | - |
68 | | -def test_shebang_posix_not_on_path(): |
69 | | - with patch_platform('posix'), patch_lookup_path(()): |
70 | | - with patch_sys_exe('python3.6'): |
71 | | - assert shebang() == '#!/usr/bin/env python3.6' |
72 | | - |
73 | | - |
74 | | -def test_shebang_posix_on_path(tmpdir): |
75 | | - exe = tmpdir.join(f'python{sys.version_info[0]}').ensure() |
76 | | - make_executable(exe) |
77 | | - |
78 | | - with patch_platform('posix'), patch_lookup_path((tmpdir.strpath,)): |
79 | | - with patch_sys_exe('python'): |
80 | | - assert shebang() == f'#!/usr/bin/env python{sys.version_info[0]}' |
81 | | - |
82 | | - |
83 | 42 | def test_install_pre_commit(in_git_dir, store): |
84 | 43 | assert not install(C.CONFIG_FILE, store, hook_types=['pre-commit']) |
85 | 44 | assert os.access(in_git_dir.join('.git/hooks/pre-commit').strpath, os.X_OK) |
@@ -336,7 +295,7 @@ def test_failing_hooks_returns_nonzero(tempdir_factory, store): |
336 | 295 | def _write_legacy_hook(path): |
337 | 296 | os.makedirs(os.path.join(path, '.git/hooks'), exist_ok=True) |
338 | 297 | with open(os.path.join(path, '.git/hooks/pre-commit'), 'w') as f: |
339 | | - f.write(f'{shebang()}\nprint("legacy hook")\n') |
| 298 | + f.write('#!/usr/bin/env bash\necho legacy hook\n') |
340 | 299 | make_executable(f.name) |
341 | 300 |
|
342 | 301 |
|
|
0 commit comments