MCPcopy Index your code
hub / github.com/pre-commit/pre-commit / test_unhealthy_then_replaced

Function test_unhealthy_then_replaced

tests/languages/python_test.py:257–282  ·  view source on GitHub ↗
(python_dir)

Source from the content-addressed store, hash-verified

255
256
257def test_unhealthy_then_replaced(python_dir):
258 prefix, tmpdir = python_dir
259
260 python.install_environment(prefix, C.DEFAULT, ())
261
262 # simulate an exe which returns an old version
263 exe_name = win_exe('python')
264 py_exe = prefix.path(python.bin_dir('py_env-default'), exe_name)
265 os.rename(py_exe, f'{py_exe}.tmp')
266
267 with open(py_exe, 'w') as f:
268 f.write('#!/usr/bin/env bash\necho 1.2.3\n')
269 make_executable(py_exe)
270
271 # should be unhealthy due to version mismatch
272 ret = python.health_check(prefix, C.DEFAULT)
273 assert ret == (
274 f'virtualenv python version did not match created version:\n'
275 f'- actual version: 1.2.3\n'
276 f'- expected version: {python._version_info(sys.executable)}\n'
277 )
278
279 # now put the exe back and it should be healthy again
280 os.replace(f'{py_exe}.tmp', py_exe)
281
282 assert python.health_check(prefix, C.DEFAULT) is None
283
284
285def test_language_versioned_python_hook(tmp_path):

Callers

nothing calls this directly

Calls 5

win_exeFunction · 0.90
make_executableFunction · 0.90
install_environmentMethod · 0.80
pathMethod · 0.80
health_checkMethod · 0.80

Tested by

no test coverage detected