MCPcopy
hub / github.com/pex-tool/pex / test_pyenv_shims

Method test_pyenv_shims

tests/test_interpreter.py:221–315  ·  view source on GitHub ↗
(self, tmpdir)

Source from the content-addressed store, hash-verified

219 assert os.path.basename(expected_interpreter.binary) != "jake"
220
221 def test_pyenv_shims(self, tmpdir):
222 # type: (Any) -> None
223 py39_dist = ensure_python_distribution(PY39)
224 py39 = py39_dist.binary
225 run_pyenv = py39_dist.run_pyenv
226
227 py311 = ensure_python_interpreter(PY311)
228
229 pyenv_root = str(run_pyenv(["root"]).strip())
230 pyenv_shims = os.path.join(pyenv_root, "shims")
231
232 def pyenv_global(*versions, **kwargs):
233 # type: (*str, **str) -> None
234 run_pyenv(["global"] + list(versions), **kwargs)
235
236 def pyenv_local(*versions, **kwargs):
237 # type: (*str, **str) -> None
238 run_pyenv(["local"] + list(versions), **kwargs)
239
240 @contextmanager
241 def pyenv_shell(*versions):
242 # type: (*str) -> Iterator[None]
243 with environment_as(PYENV_VERSION=":".join(versions)):
244 yield
245
246 pex_root = os.path.join(str(tmpdir), "pex_root")
247 cwd = safe_mkdir(os.path.join(str(tmpdir), "home", "jake", "project"))
248 with ENV.patch(PEX_ROOT=pex_root) as pex_env, environment_as(
249 **dict(pex_env, PYENV_ROOT=pyenv_root, PEX_PYTHON_PATH=pyenv_shims)
250 ), pyenv_shell():
251 pyenv = Pyenv.find()
252 assert pyenv is not None
253 assert pyenv_root == pyenv.root
254
255 def interpreter_for_shim(shim_name):
256 # type: (str) -> PythonInterpreter
257 binary = os.path.join(pyenv_shims, shim_name)
258 return PythonInterpreter.from_binary(binary, pyenv=pyenv, cwd=cwd)
259
260 def assert_shim(
261 shim_name, # type: str
262 expected_binary_path, # type: str
263 ):
264 # type: (...) -> None
265 python = interpreter_for_shim(shim_name)
266 assert expected_binary_path == python.binary
267
268 def assert_shim_inactive(shim_name):
269 # type: (str) -> None
270 with pytest.raises(PythonInterpreter.IdentificationError):
271 interpreter_for_shim(shim_name)
272
273 pyenv_global(PY39, PY311, cwd=cwd)
274 assert_shim("python", py39)
275 assert_shim("python3", py39)
276 assert_shim("python3.9", py39)
277 assert_shim("python3.11", py311)
278

Callers

nothing calls this directly

Calls 9

safe_mkdirFunction · 0.90
environment_asFunction · 0.90
safe_renameFunction · 0.90
stripMethod · 0.80
joinMethod · 0.45
patchMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected