|
11 | 11 |
|
12 | 12 | import pytest
|
13 | 13 |
|
14 |
| -from virtualenv.discovery.builtin import Builtin, get_interpreter |
| 14 | +from virtualenv.discovery.builtin import Builtin, LazyPathDump, get_interpreter, get_paths |
15 | 15 | from virtualenv.discovery.py_info import PythonInfo
|
16 |
| -from virtualenv.info import fs_supports_symlink |
| 16 | +from virtualenv.info import IS_WIN, fs_supports_symlink |
17 | 17 |
|
18 | 18 |
|
19 | 19 | @pytest.mark.skipif(not fs_supports_symlink(), reason="symlink not supported")
|
@@ -200,6 +200,14 @@ def test_returns_second_python_specified_when_more_than_one_is_specified_and_env
|
200 | 200 | assert result == mocker.sentinel.python_from_cli
|
201 | 201 |
|
202 | 202 |
|
| 203 | +def test_discovery_via_path_with_file(tmp_path, monkeypatch): |
| 204 | + a_file = tmp_path / "a_file" |
| 205 | + a_file.touch() |
| 206 | + monkeypatch.setenv("PATH", str(a_file)) |
| 207 | + interpreter = get_interpreter(uuid4().hex, []) |
| 208 | + assert interpreter is None |
| 209 | + |
| 210 | + |
203 | 211 | def test_absolute_path_does_not_exist(tmp_path):
|
204 | 212 | """
|
205 | 213 | Test that virtualenv does not fail when an absolute path that does not exist is provided.
|
@@ -255,6 +263,24 @@ def test_absolute_path_does_not_exist_fails(tmp_path):
|
255 | 263 | assert process.returncode != 0, process.stderr
|
256 | 264 |
|
257 | 265 |
|
| 266 | +def test_get_paths_no_path_env(monkeypatch): |
| 267 | + monkeypatch.delenv("PATH", raising=False) |
| 268 | + paths = list(get_paths({})) |
| 269 | + assert paths |
| 270 | + |
| 271 | + |
| 272 | +def test_lazy_path_dump_debug(monkeypatch, tmp_path): |
| 273 | + monkeypatch.setenv("_VIRTUALENV_DEBUG", "1") |
| 274 | + a_dir = tmp_path |
| 275 | + executable_file = "a_file.exe" if IS_WIN else "a_file" |
| 276 | + (a_dir / executable_file).touch(mode=0o755) |
| 277 | + (a_dir / "b_file").touch(mode=0o644) |
| 278 | + dumper = LazyPathDump(0, a_dir, os.environ) |
| 279 | + output = repr(dumper) |
| 280 | + assert executable_file in output |
| 281 | + assert "b_file" not in output |
| 282 | + |
| 283 | + |
258 | 284 | @pytest.mark.usefixtures("mock_get_interpreter")
|
259 | 285 | def test_returns_first_python_specified_when_no_env_var_is_specified(mocker, monkeypatch, session_app_data):
|
260 | 286 | monkeypatch.delenv("VIRTUALENV_PYTHON", raising=False)
|
|
0 commit comments