summaryrefslogtreecommitdiff
path: root/tests/functional/test_new_resolver_target.py
blob: 811ae935aec6f95d194f70912c7eafba81f84b4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from pathlib import Path
from typing import Callable, Optional

import pytest

from pip._internal.cli.status_codes import ERROR, SUCCESS
from tests.lib import PipTestEnvironment
from tests.lib.wheel import make_wheel

MakeFakeWheel = Callable[[str], str]


@pytest.fixture()
def make_fake_wheel(script: PipTestEnvironment) -> MakeFakeWheel:
    def _make_fake_wheel(wheel_tag: str) -> str:
        wheel_house = script.scratch_path.joinpath("wheelhouse")
        wheel_house.mkdir()
        wheel_builder = make_wheel(
            name="fake",
            version="1.0",
            wheel_metadata_updates={"Tag": []},
        )
        wheel_path = wheel_house.joinpath(f"fake-1.0-{wheel_tag}.whl")
        wheel_builder.save_to(wheel_path)
        return str(wheel_path)

    return _make_fake_wheel


@pytest.mark.parametrize("implementation", [None, "fakepy"])
@pytest.mark.parametrize("python_version", [None, "1"])
@pytest.mark.parametrize("abi", [None, "fakeabi"])
@pytest.mark.parametrize("platform", [None, "fakeplat"])
def test_new_resolver_target_checks_compatibility_failure(
    script: PipTestEnvironment,
    make_fake_wheel: MakeFakeWheel,
    implementation: Optional[str],
    python_version: Optional[str],
    abi: Optional[str],
    platform: Optional[str],
) -> None:
    fake_wheel_tag = "fakepy1-fakeabi-fakeplat"
    args = [
        "install",
        "--only-binary=:all:",
        "--no-cache-dir",
        "--no-index",
        "--target",
        str(script.scratch_path.joinpath("target")),
        make_fake_wheel(fake_wheel_tag),
    ]
    if implementation:
        args += ["--implementation", implementation]
    if python_version:
        args += ["--python-version", python_version]
    if abi:
        args += ["--abi", abi]
    if platform:
        args += ["--platform", platform]

    args_tag = "{}{}-{}-{}".format(
        implementation,
        python_version,
        abi,
        platform,
    )
    wheel_tag_matches = args_tag == fake_wheel_tag

    result = script.pip(*args, expect_error=(not wheel_tag_matches))

    dist_info = Path("scratch", "target", "fake-1.0.dist-info")
    if wheel_tag_matches:
        assert result.returncode == SUCCESS
        result.did_create(dist_info)
    else:
        assert result.returncode == ERROR
        result.did_not_create(dist_info)