1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00
pip/tests/unit/test_utils_distutils_args.py
Chris Hunt 55a943e556 Add distutils args helpers
The utils.distutils_args.parse_args function can recognize distutils
arguments so we can deprecate their usage.
2019-11-30 17:39:56 -05:00

60 lines
1.6 KiB
Python

import pytest
from pip._internal.utils.distutils_args import parse_distutils_args
def test_unknown_option_is_ok():
result = parse_distutils_args(["--foo"])
assert not result
def test_option_is_returned():
result = parse_distutils_args(["--prefix=hello"])
assert result["prefix"] == "hello"
def test_options_are_clobbered():
# 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():
result = parse_distutils_args(["--prefix=hello", "--root=world"])
assert result["prefix"] == "hello"
assert result["root"] == "world"
def test_multiple_invocations_do_not_keep_options():
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, value):
result = parse_distutils_args(["--{}={}".format(name, value)])
key_name = name.replace("-", "_")
assert result[key_name] == value
def test_user_option_works():
result = parse_distutils_args(["--user"])
assert result["user"] == 1