Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions tests/test_discovery.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import copy
import logging
import os
import stat
Expand Down Expand Up @@ -138,14 +139,17 @@ def test_discovery_invalid_specifier_raises(session_cache: DiskCache) -> None:
[pytest.param(False, id="list"), pytest.param(True, id="iterator")],
)
def test_discovery_fallback_reuses_preferred_paths(
tmp_path: Path, session_cache: DiskCache, *, use_iterator: bool
tmp_path: Path, session_cache: DiskCache, mocker: MockerFixture, *, use_iterator: bool
) -> None:
preferred = tmp_path / "preferred"
subprocess.check_call([sys.executable, "-m", "venv", "--without-pip", "--copies", str(preferred)])
executable = preferred / ("Scripts/python.exe" if IS_WIN else "bin/python")
executable = tmp_path / "preferred" / ("Scripts/python.exe" if IS_WIN else "bin/python")
executable.parent.mkdir(parents=True)
executable.touch()
preferred_info = copy.deepcopy(PythonInfo.current_system(session_cache))
preferred_info.executable = str(executable)
mocker.patch.object(PythonInfo, "from_exe", return_value=preferred_info)
paths = [str(executable)]
result = get_interpreter(
["missing-interpreter", str(sys.version_info.major)],
["missing-interpreter", ">=3"],
try_first_with=iter(paths) if use_iterator else paths,
cache=session_cache,
env={**os.environ, "PATH": str(tmp_path), "UV_PYTHON_INSTALL_DIR": str(tmp_path / "missing")},
Expand All @@ -157,7 +161,7 @@ def test_discovery_fallback_reuses_preferred_paths(

def test_discovery_stops_reading_preferred_paths_after_match(session_cache: DiskCache) -> None:
preferred_paths = iter([sys.executable, "unneeded"])
result = get_interpreter(str(sys.version_info.major), try_first_with=preferred_paths, cache=session_cache)
result = get_interpreter(">=3", try_first_with=preferred_paths, cache=session_cache)
assert result is not None
assert next(preferred_paths) == "unneeded"

Expand Down