|
8 | 8 | from pre_commit.envcontext import envcontext |
9 | 9 | from pre_commit.languages import python |
10 | 10 | from pre_commit.prefix import Prefix |
| 11 | +from pre_commit.util import make_executable |
11 | 12 |
|
12 | 13 |
|
13 | 14 | def test_read_pyvenv_cfg(tmpdir): |
@@ -141,3 +142,26 @@ def test_unhealthy_old_virtualenv(python_dir): |
141 | 142 | os.remove(prefix.path('py_env-default/pyvenv.cfg')) |
142 | 143 |
|
143 | 144 | assert python.healthy(prefix, C.DEFAULT) is False |
| 145 | + |
| 146 | + |
| 147 | +def test_unhealthy_then_replaced(python_dir): |
| 148 | + prefix, tmpdir = python_dir |
| 149 | + |
| 150 | + python.install_environment(prefix, C.DEFAULT, ()) |
| 151 | + |
| 152 | + # simulate an exe which returns an old version |
| 153 | + exe_name = 'python.exe' if sys.platform == 'win32' else 'python' |
| 154 | + py_exe = prefix.path(python.bin_dir('py_env-default'), exe_name) |
| 155 | + os.rename(py_exe, f'{py_exe}.tmp') |
| 156 | + |
| 157 | + with open(py_exe, 'w') as f: |
| 158 | + f.write('#!/usr/bin/env bash\necho 1.2.3\n') |
| 159 | + make_executable(py_exe) |
| 160 | + |
| 161 | + # should be unhealthy due to version mismatch |
| 162 | + assert python.healthy(prefix, C.DEFAULT) is False |
| 163 | + |
| 164 | + # now put the exe back and it should be healthy again |
| 165 | + os.replace(f'{py_exe}.tmp', py_exe) |
| 166 | + |
| 167 | + assert python.healthy(prefix, C.DEFAULT) is True |
0 commit comments