2019-11-17 00:00:34 +01:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from pip._internal.utils.distutils_args import parse_distutils_args
|
|
|
|
|
|
|
|
|
2021-08-30 00:43:28 +02:00
|
|
|
def test_unknown_option_is_ok() -> None:
|
2019-11-17 00:00:34 +01:00
|
|
|
result = parse_distutils_args(["--foo"])
|
|
|
|
assert not result
|
|
|
|
|
|
|
|
|
2021-08-30 00:43:28 +02:00
|
|
|
def test_option_is_returned() -> None:
|
2019-11-17 00:00:34 +01:00
|
|
|
result = parse_distutils_args(["--prefix=hello"])
|
|
|
|
assert result["prefix"] == "hello"
|
|
|
|
|
|
|
|
|
2021-08-30 00:43:28 +02:00
|
|
|
def test_options_are_clobbered() -> None:
|
2019-11-17 00:00:34 +01:00
|
|
|
# Matches the current setuptools behavior that the last argument
|
|
|
|
# wins.
|
|
|
|
result = parse_distutils_args(["--prefix=hello", "--prefix=world"])
|
|
|
|
assert result["prefix"] == "world"
|
|
|
|
|
|
|
|
|
2021-08-30 00:43:28 +02:00
|
|
|
def test_multiple_options_work() -> None:
|
2019-11-17 00:00:34 +01:00
|
|
|
result = parse_distutils_args(["--prefix=hello", "--root=world"])
|
|
|
|
assert result["prefix"] == "hello"
|
|
|
|
assert result["root"] == "world"
|
|
|
|
|
|
|
|
|
2021-08-30 00:43:28 +02:00
|
|
|
def test_multiple_invocations_do_not_keep_options() -> None:
|
2019-11-17 00:00:34 +01:00
|
|
|
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"
|
|
|
|
|
|
|
|
|
2021-08-13 15:23:45 +02:00
|
|
|
@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"),
|
|
|
|
],
|
|
|
|
)
|
2021-08-30 00:43:28 +02:00
|
|
|
def test_all_value_options_work(name: str, value: str) -> None:
|
2020-12-23 20:25:12 +01:00
|
|
|
result = parse_distutils_args([f"--{name}={value}"])
|
2019-11-17 00:00:34 +01:00
|
|
|
key_name = name.replace("-", "_")
|
|
|
|
assert result[key_name] == value
|
|
|
|
|
|
|
|
|
2021-08-30 00:43:28 +02:00
|
|
|
def test_user_option_works() -> None:
|
2019-11-17 00:00:34 +01:00
|
|
|
result = parse_distutils_args(["--user"])
|
|
|
|
assert result["user"] == 1
|