|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import pathlib |
| 4 | +import typing as _t |
| 5 | + |
3 | 6 | import pytest |
| 7 | +from pip._internal.req import InstallRequirement |
| 8 | +from pytest_mock import MockerFixture |
4 | 9 |
|
5 | | -from piptools.repositories.pypi import _get_true_base_from_index_url |
| 10 | +from piptools.repositories.pypi import PyPIRepository, _get_true_base_from_index_url |
| 11 | +from tests.constants import PACKAGES_PATH |
6 | 12 |
|
7 | 13 |
|
8 | 14 | @pytest.mark.parametrize( |
|
48 | 54 | ) |
49 | 55 | def test_true_base_url_strips_simple_suffix(url: str, expect_result: str) -> None: |
50 | 56 | assert _get_true_base_from_index_url(url) == expect_result |
| 57 | + |
| 58 | + |
| 59 | +@pytest.mark.parametrize( |
| 60 | + "requirement_string", |
| 61 | + ( |
| 62 | + pytest.param("django", id="unbound"), |
| 63 | + pytest.param("django > 1", id="lower-bound"), |
| 64 | + ), |
| 65 | +) |
| 66 | +def test_get_dependencies_helper_rejects_unpinned_reqs( |
| 67 | + pypi_repository: PyPIRepository, |
| 68 | + from_line: _t.Callable[[str], InstallRequirement], |
| 69 | + requirement_string: str, |
| 70 | +) -> None: |
| 71 | + ireq = from_line(requirement_string) |
| 72 | + with pytest.raises( |
| 73 | + TypeError, match="Expected url, pinned or editable InstallRequirement" |
| 74 | + ): |
| 75 | + pypi_repository.get_dependencies(ireq) |
| 76 | + |
| 77 | + |
| 78 | +def test_find_best_match_short_circuits_on_editables( |
| 79 | + mocker: MockerFixture, |
| 80 | + pypi_repository: PyPIRepository, |
| 81 | + from_editable: _t.Callable[[str], InstallRequirement], |
| 82 | +) -> None: |
| 83 | + package_path = pathlib.Path(PACKAGES_PATH) / "small_fake_a" |
| 84 | + ireq = from_editable(str(package_path)) |
| 85 | + |
| 86 | + mock_find_all_candidates = mocker.patch.object( |
| 87 | + pypi_repository, |
| 88 | + "find_all_candidates", |
| 89 | + wraps=pypi_repository.find_all_candidates, |
| 90 | + ) |
| 91 | + |
| 92 | + assert pypi_repository.find_best_match(ireq) is ireq |
| 93 | + mock_find_all_candidates.assert_not_called() |
0 commit comments