|
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 |
|
| 5 | +import usethis |
| 6 | +import usethis._integrations |
| 7 | +import usethis._integrations.uv |
| 8 | +import usethis._integrations.uv.deps |
5 | 9 | from usethis._config import usethis_config |
6 | 10 | from usethis._integrations.pyproject_toml.core import ( |
7 | 11 | get_pyproject_value, |
|
18 | 22 | register_default_group, |
19 | 23 | remove_deps_from_group, |
20 | 24 | ) |
| 25 | +from usethis._integrations.uv.errors import UVDepGroupError, UVSubprocessFailedError |
21 | 26 | from usethis._test import change_cwd |
22 | 27 |
|
23 | 28 |
|
@@ -272,6 +277,30 @@ def test_dev_group_not_registered(self, uv_init_dir: Path): |
272 | 277 | # Tool section shouldn't even exist in pyproject.toml |
273 | 278 | assert "tool" not in (uv_init_dir / "pyproject.toml").read_text() |
274 | 279 |
|
| 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 | + |
275 | 304 |
|
276 | 305 | class TestRemoveDepsFromGroup: |
277 | 306 | @pytest.mark.usefixtures("_vary_network_conn") |
@@ -395,6 +424,35 @@ def test_group_not_in_dependency_groups( |
395 | 424 | assert not err |
396 | 425 | assert not out |
397 | 426 |
|
| 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 | + |
398 | 456 |
|
399 | 457 | class TestIsDepInAnyGroup: |
400 | 458 | def test_no_group(self, uv_init_dir: Path): |
|
0 commit comments