|
20 | 20 | import shutil |
21 | 21 | import subprocess |
22 | 22 | import sys |
| 23 | +import types |
23 | 24 | from textwrap import dedent |
24 | 25 | from typing import NamedTuple |
25 | 26 | from unittest import mock |
@@ -546,6 +547,32 @@ def test_create_reuse_uv_environment(make_one): |
546 | 547 | assert reused |
547 | 548 |
|
548 | 549 |
|
| 550 | +UV_IN_PIPX_VENV = "/home/user/.local/pipx/venvs/nox/bin/uv" |
| 551 | + |
| 552 | + |
| 553 | +@pytest.mark.parametrize( |
| 554 | + ["which_result", "find_uv_bin_result", "expected"], |
| 555 | + [ |
| 556 | + ("/usr/bin/uv", UV_IN_PIPX_VENV, (True, UV_IN_PIPX_VENV)), |
| 557 | + ("/usr/bin/uv", FileNotFoundError, (True, "/usr/bin/uv")), |
| 558 | + (None, UV_IN_PIPX_VENV, (True, UV_IN_PIPX_VENV)), |
| 559 | + (None, FileNotFoundError, (False, "uv")), |
| 560 | + ], |
| 561 | +) # fmt: skip |
| 562 | +def test_find_uv(monkeypatch, which_result, find_uv_bin_result, expected): |
| 563 | + def find_uv_bin(): |
| 564 | + if find_uv_bin_result is FileNotFoundError: |
| 565 | + raise FileNotFoundError |
| 566 | + return find_uv_bin_result |
| 567 | + |
| 568 | + monkeypatch.setattr(shutil, "which", lambda _: which_result) |
| 569 | + monkeypatch.setitem( |
| 570 | + sys.modules, "uv", types.SimpleNamespace(find_uv_bin=find_uv_bin) |
| 571 | + ) |
| 572 | + |
| 573 | + assert nox.virtualenv.find_uv() == expected |
| 574 | + |
| 575 | + |
549 | 576 | def test_create_reuse_venv_environment(make_one, monkeypatch): |
550 | 577 | # Making the reuse requirement more strict |
551 | 578 | monkeypatch.setenv("NOX_ENABLE_STALENESS_CHECK", "1") |
|
0 commit comments