diff --git a/tests/unit/discovery/test_discovery.py b/tests/unit/discovery/test_discovery.py index dd32ba27a..b17ed4ea6 100644 --- a/tests/unit/discovery/test_discovery.py +++ b/tests/unit/discovery/test_discovery.py @@ -5,7 +5,6 @@ import sys from argparse import Namespace from pathlib import Path -from typing import TYPE_CHECKING from uuid import uuid4 import pytest @@ -14,22 +13,28 @@ from virtualenv.discovery.py_info import PythonInfo from virtualenv.info import fs_supports_symlink -if TYPE_CHECKING: - from virtualenv.app_data.base import AppData - @pytest.mark.skipif(not fs_supports_symlink(), reason="symlink not supported") @pytest.mark.parametrize("case", ["mixed", "lower", "upper"]) -def test_discovery_via_path(monkeypatch, case, tmp_path, caplog, session_app_data): +@pytest.mark.parametrize("specificity", ["more", "less"]) +def test_discovery_via_path(monkeypatch, case, specificity, tmp_path, caplog, session_app_data): # noqa: PLR0913 caplog.set_level(logging.DEBUG) current = PythonInfo.current_system(session_app_data) - core = f"somethingVeryCryptic{'.'.join(str(i) for i in current.version_info[0:3])}" name = "somethingVeryCryptic" if case == "lower": name = name.lower() elif case == "upper": name = name.upper() - exe_name = f"{name}{current.version_info.major}{'.exe' if sys.platform == 'win32' else ''}" + if specificity == "more": + # e.g. spec: python3, exe: /bin/python3.12 + core_ver = current.version_info.major + exe_ver = ".".join(str(i) for i in current.version_info[0:2]) + elif specificity == "less": + # e.g. spec: python3.12.1, exe: /bin/python3 + core_ver = ".".join(str(i) for i in current.version_info[0:3]) + exe_ver = current.version_info.major + core = f"{name}{core_ver}" + exe_name = f"{name}{exe_ver}{'.exe' if sys.platform == 'win32' else ''}" target = tmp_path / current.install_path("scripts") target.mkdir(parents=True) executable = target / exe_name @@ -44,29 +49,6 @@ def test_discovery_via_path(monkeypatch, case, tmp_path, caplog, session_app_dat assert interpreter is not None -@pytest.mark.skipif(not fs_supports_symlink(), reason="symlink not supported") -def test_discovery_via_path_specific( - monkeypatch: pytest.MonkeyPatch, tmp_path: Path, caplog: pytest.LogCaptureFixture, session_app_data: AppData -): - """Test that a generic spec (e.g. python3) can be used to find a specific interpreter (e.g. python3.12)""" - caplog.set_level(logging.DEBUG) - current = PythonInfo.current_system(session_app_data) - name = "somethingVeryCryptic" - spec = f"{name}{current.version_info.major}" - exe_name = f"{name}{'.'.join(str(i) for i in current.version_info[:2])}{'.exe' if sys.platform == 'win32' else ''}" - target = tmp_path / current.install_path("scripts") - target.mkdir(parents=True) - executable = target / exe_name - os.symlink(sys.executable, str(executable)) - pyvenv_cfg = Path(sys.executable).parents[1] / "pyvenv.cfg" - if pyvenv_cfg.exists(): - (target / pyvenv_cfg.name).write_bytes(pyvenv_cfg.read_bytes()) - monkeypatch.setenv("PATH", str(target)) - interpreter = get_interpreter(spec, []) - - assert interpreter is not None - - def test_discovery_via_path_not_found(tmp_path, monkeypatch): monkeypatch.setenv("PATH", str(tmp_path)) interpreter = get_interpreter(uuid4().hex, [])