Skip to content

Commit 9d40953

Browse files
Add tests cases for when uv subprocess fails
1 parent 6e81993 commit 9d40953

2 files changed

Lines changed: 59 additions & 5 deletions

File tree

tests/usethis/_core/test_core_tool.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,7 @@ def test_no_pyproject_toml(
198198
# Set python version
199199
(tmp_path / ".python-version").write_text(get_python_version())
200200

201-
with (
202-
change_cwd(tmp_path),
203-
PyprojectTOMLManager(),
204-
usethis_config.set(subprocess_verbose=True),
205-
):
201+
with change_cwd(tmp_path), PyprojectTOMLManager():
206202
# Act
207203
use_coverage()
208204

tests/usethis/_integrations/uv/test_deps.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
import pytest
44

5+
import usethis
6+
import usethis._integrations
7+
import usethis._integrations.uv
8+
import usethis._integrations.uv.deps
59
from usethis._config import usethis_config
610
from usethis._integrations.pyproject_toml.core import (
711
get_pyproject_value,
@@ -18,6 +22,7 @@
1822
register_default_group,
1923
remove_deps_from_group,
2024
)
25+
from usethis._integrations.uv.errors import UVDepGroupError, UVSubprocessFailedError
2126
from usethis._test import change_cwd
2227

2328

@@ -272,6 +277,30 @@ def test_dev_group_not_registered(self, uv_init_dir: Path):
272277
# Tool section shouldn't even exist in pyproject.toml
273278
assert "tool" not in (uv_init_dir / "pyproject.toml").read_text()
274279

280+
def test_uv_subprocess_error(
281+
self,
282+
uv_init_dir: Path,
283+
monkeypatch: pytest.MonkeyPatch,
284+
capfd: pytest.CaptureFixture[str],
285+
):
286+
def mock_call_uv_subprocess(*_, **__):
287+
raise UVSubprocessFailedError
288+
289+
monkeypatch.setattr(
290+
usethis._integrations.uv.deps, "call_uv_subprocess", mock_call_uv_subprocess
291+
)
292+
293+
with (
294+
change_cwd(uv_init_dir),
295+
PyprojectTOMLManager(),
296+
pytest.raises(
297+
UVDepGroupError,
298+
match="Failed to add 'pytest' to the 'test' dependency group",
299+
),
300+
):
301+
# Act
302+
add_deps_to_group([Dependency(name="pytest")], "test")
303+
275304

276305
class TestRemoveDepsFromGroup:
277306
@pytest.mark.usefixtures("_vary_network_conn")
@@ -395,6 +424,35 @@ def test_group_not_in_dependency_groups(
395424
assert not err
396425
assert not out
397426

427+
def test_uv_subprocess_error(
428+
self,
429+
uv_init_dir: Path,
430+
monkeypatch: pytest.MonkeyPatch,
431+
capfd: pytest.CaptureFixture[str],
432+
):
433+
with (
434+
change_cwd(uv_init_dir),
435+
PyprojectTOMLManager(),
436+
):
437+
# Arrange
438+
add_deps_to_group([Dependency(name="pytest")], "test")
439+
440+
def mock_call_uv_subprocess(*_, **__):
441+
raise UVSubprocessFailedError
442+
443+
monkeypatch.setattr(
444+
usethis._integrations.uv.deps,
445+
"call_uv_subprocess",
446+
mock_call_uv_subprocess,
447+
)
448+
449+
# Act
450+
with pytest.raises(
451+
UVDepGroupError,
452+
match="Failed to remove 'pytest' from the 'test' dependency group",
453+
):
454+
remove_deps_from_group([Dependency(name="pytest")], "test")
455+
398456

399457
class TestIsDepInAnyGroup:
400458
def test_no_group(self, uv_init_dir: Path):

0 commit comments

Comments
 (0)