|
1 | 1 | from pathlib import Path |
| 2 | +from unittest.mock import MagicMock |
2 | 3 |
|
3 | 4 | import pytest |
4 | 5 |
|
| 6 | +from depgather.native import NativeInfer |
5 | 7 | from depgather.parse import ResolverName, gather |
6 | 8 | from depgather.utils import enable_verbose |
| 9 | +from tests.utils import assert_eq_packages |
7 | 10 |
|
8 | 11 | THISDIR = Path(__file__).resolve().parent |
9 | 12 | enable_verbose() |
@@ -36,3 +39,114 @@ def test_lockfiles(resolvername: ResolverName) -> None: |
36 | 39 | requirementsPath=requirementsPath, |
37 | 40 | preferred_resolver=resolvername, |
38 | 41 | ) |
| 42 | + |
| 43 | + |
| 44 | +@pytest.mark.parametrize( |
| 45 | + ("lockfile", "extradelta"), |
| 46 | + [ |
| 47 | + ("poetry.lock", {"pip", "uv", "pygments"}), |
| 48 | + ("uv_.lock", {"pip", "uv", "depgather"}), |
| 49 | + ("pylock.toml", {"depgather"}), |
| 50 | + ], |
| 51 | +) |
| 52 | +def test_lockfiles_fav_uv( |
| 53 | + monkeypatch: pytest.MonkeyPatch, lockfile: str, extradelta: set[str] |
| 54 | +) -> None: |
| 55 | + """This takes the minimal lockfiles from the following commands as applied to this library |
| 56 | +
|
| 57 | + The commands to generate these files are as follows: |
| 58 | + uvx poetry lock |
| 59 | + uv export --format pylock.toml > pylock |
| 60 | + uv sync |
| 61 | + """ |
| 62 | + |
| 63 | + mock = MagicMock(wraps=NativeInfer.gather) |
| 64 | + |
| 65 | + monkeypatch.setattr( |
| 66 | + NativeInfer, |
| 67 | + "gather", |
| 68 | + mock, |
| 69 | + ) |
| 70 | + |
| 71 | + requirementsPath: Path = THISDIR / "data/example1" / lockfile |
| 72 | + skipDependencies: set[str] = {"TOSKIP"} |
| 73 | + |
| 74 | + deps = gather( |
| 75 | + skipDependencies=skipDependencies, |
| 76 | + extras=set(), |
| 77 | + groups=set(), |
| 78 | + requirementsPath=requirementsPath, |
| 79 | + preferred_resolver=ResolverName.UV, |
| 80 | + ) |
| 81 | + |
| 82 | + mock.assert_called_once() |
| 83 | + |
| 84 | + expected = { |
| 85 | + "basedpyright", |
| 86 | + "colorama", |
| 87 | + "coverage", |
| 88 | + "iniconfig", |
| 89 | + "nodejs-wheel-binaries", |
| 90 | + "packaging", |
| 91 | + "pluggy", |
| 92 | + "pytest", |
| 93 | + "requirements-parser", |
| 94 | + "ruff", |
| 95 | + "tomli", |
| 96 | + } |
| 97 | + |
| 98 | + assert len(deps) == len(expected) + len(extradelta) |
| 99 | + |
| 100 | + # assert depgather.native.NativeInfer.gather( called |
| 101 | + |
| 102 | + assert_eq_packages(deps, expected | extradelta) |
| 103 | + |
| 104 | + |
| 105 | +@pytest.mark.parametrize( |
| 106 | + ("sbom"), |
| 107 | + [ |
| 108 | + ("cyclonedx.json"), |
| 109 | + ("spdx.json"), |
| 110 | + ], |
| 111 | +) |
| 112 | +def test_sbom_fav_uv(monkeypatch: pytest.MonkeyPatch, sbom: str) -> None: |
| 113 | + """This takes the minimal sbom from as applied to depgather (with the dev group, |
| 114 | + no extras) |
| 115 | + """ |
| 116 | + |
| 117 | + mock = MagicMock(wraps=NativeInfer.gather) |
| 118 | + |
| 119 | + monkeypatch.setattr( |
| 120 | + NativeInfer, |
| 121 | + "gather", |
| 122 | + mock, |
| 123 | + ) |
| 124 | + sbomPath: Path = THISDIR / "data" / sbom |
| 125 | + |
| 126 | + deps = gather( |
| 127 | + requirementsPath=sbomPath, |
| 128 | + skipDependencies=set(), |
| 129 | + extras=set(), |
| 130 | + groups={"dev"}, |
| 131 | + preferred_resolver=ResolverName.UV, |
| 132 | + ) |
| 133 | + |
| 134 | + mock.assert_called_once() |
| 135 | + |
| 136 | + expected = { |
| 137 | + "basedpyright", |
| 138 | + "colorama", # windows only requirement |
| 139 | + "coverage", |
| 140 | + "iniconfig", |
| 141 | + "nodejs-wheel-binaries", |
| 142 | + "packaging", |
| 143 | + "pluggy", |
| 144 | + "pytest", |
| 145 | + "requirements-parser", |
| 146 | + "ruff", |
| 147 | + "tomli", |
| 148 | + "loguru", |
| 149 | + "win32-setctime", |
| 150 | + } |
| 151 | + |
| 152 | + assert_eq_packages(deps, expected) |
0 commit comments