summaryrefslogtreecommitdiff
path: root/tests/unit/test_pyproject_config.py
blob: c7e46956055f5d9f258640ffac2f5814f1c3b9ae (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
from typing import Dict, List

import pytest

from pip._internal.commands import create_command


@pytest.mark.parametrize(
    ("command", "expected"),
    [
        ("install", True),
        ("wheel", True),
        ("freeze", False),
    ],
)
def test_supports_config(command: str, expected: bool) -> None:
    c = create_command(command)
    options, _ = c.parse_args([])
    assert hasattr(options, "config_settings") == expected


def test_set_config_value_true() -> None:
    i = create_command("install")
    # Invalid argument exits with an error
    with pytest.raises(SystemExit):
        options, _ = i.parse_args(["xxx", "--config-settings", "x"])


def test_set_config_value() -> None:
    i = create_command("install")
    options, _ = i.parse_args(["xxx", "--config-settings", "x=hello"])
    assert options.config_settings == {"x": "hello"}


def test_set_config_empty_value() -> None:
    i = create_command("install")
    options, _ = i.parse_args(["xxx", "--config-settings", "x="])
    assert options.config_settings == {"x": ""}


@pytest.mark.parametrize(
    ("passed", "expected"),
    [
        (["x=hello", "x=world"], {"x": ["hello", "world"]}),
        (["x=hello", "x=world", "x=other"], {"x": ["hello", "world", "other"]}),
    ],
)
def test_multiple_config_values(passed: List[str], expected: Dict[str, str]) -> None:
    i = create_command("install")
    options, _ = i.parse_args(
        ["xxx", *(f"--config-settings={option}" for option in passed)]
    )
    assert options.config_settings == expected