summaryrefslogtreecommitdiff
path: root/tests/unit/test_utils_distutils_args.py
blob: 21f31e926f29a8007b600252c3dda8f37d32266d (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
import pytest

from pip._internal.utils.distutils_args import parse_distutils_args


def test_unknown_option_is_ok() -> None:
    result = parse_distutils_args(["--foo"])
    assert not result


def test_option_is_returned() -> None:
    result = parse_distutils_args(["--prefix=hello"])
    assert result["prefix"] == "hello"


def test_options_are_clobbered() -> None:
    # Matches the current setuptools behavior that the last argument
    # wins.
    result = parse_distutils_args(["--prefix=hello", "--prefix=world"])
    assert result["prefix"] == "world"


def test_multiple_options_work() -> None:
    result = parse_distutils_args(["--prefix=hello", "--root=world"])
    assert result["prefix"] == "hello"
    assert result["root"] == "world"


def test_multiple_invocations_do_not_keep_options() -> None:
    result = parse_distutils_args(["--prefix=hello1"])
    assert len(result) == 1
    assert result["prefix"] == "hello1"

    result = parse_distutils_args(["--root=world1"])
    assert len(result) == 1
    assert result["root"] == "world1"


@pytest.mark.parametrize(
    "name,value",
    [
        ("exec-prefix", "1"),
        ("home", "2"),
        ("install-base", "3"),
        ("install-data", "4"),
        ("install-headers", "5"),
        ("install-lib", "6"),
        ("install-platlib", "7"),
        ("install-purelib", "8"),
        ("install-scripts", "9"),
        ("prefix", "10"),
        ("root", "11"),
    ],
)
def test_all_value_options_work(name: str, value: str) -> None:
    result = parse_distutils_args([f"--{name}={value}"])
    key_name = name.replace("-", "_")
    assert result[key_name] == value


def test_user_option_works() -> None:
    result = parse_distutils_args(["--user"])
    assert result["user"]