1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00
pip/tests/unit/test_pep517.py

77 lines
2.1 KiB
Python
Raw Normal View History

from textwrap import dedent
2018-07-27 15:31:26 +02:00
import pytest
from pip._internal.exceptions import InstallationError
from pip._internal.req import InstallRequirement
2021-08-13 15:23:45 +02:00
@pytest.mark.parametrize(
("source", "expected"),
[
("pep517_setup_and_pyproject", True),
("pep517_setup_only", False),
("pep517_pyproject_only", True),
],
)
def test_use_pep517(shared_data, source, expected):
2018-07-27 15:31:26 +02:00
"""
Test that we choose correctly between PEP 517 and legacy code paths
"""
src = shared_data.src.joinpath(source)
req = InstallRequirement(None, None)
req.source_dir = src # make req believe it has been unpacked
2018-07-27 15:31:26 +02:00
req.load_pyproject_toml()
assert req.use_pep517 is expected
2021-08-13 15:23:45 +02:00
@pytest.mark.parametrize(
("source", "msg"),
[
("pep517_setup_and_pyproject", "specifies a build backend"),
("pep517_pyproject_only", "does not have a setup.py"),
],
)
def test_disabling_pep517_invalid(shared_data, source, msg):
2018-07-27 15:31:26 +02:00
"""
Test that we fail if we try to disable PEP 517 when it's not acceptable
"""
src = shared_data.src.joinpath(source)
req = InstallRequirement(None, None)
req.source_dir = src # make req believe it has been unpacked
2018-07-27 15:31:26 +02:00
# Simulate --no-use-pep517
req.use_pep517 = False
with pytest.raises(InstallationError) as e:
req.load_pyproject_toml()
err_msg = e.value.args[0]
assert "Disabling PEP 517 processing is invalid" in err_msg
assert msg in err_msg
@pytest.mark.parametrize(
("spec",), [("./foo",), ("git+https://example.com/pkg@dev#egg=myproj",)]
)
def test_pep517_parsing_checks_requirements(tmpdir, spec):
2021-08-13 15:23:45 +02:00
tmpdir.joinpath("pyproject.toml").write_text(
dedent(
"""
[build-system]
requires = [{!r}]
build-backend = "foo"
2021-08-13 15:23:45 +02:00
""".format(
spec
)
)
)
req = InstallRequirement(None, None)
req.source_dir = tmpdir # make req believe it has been unpacked
with pytest.raises(InstallationError) as e:
req.load_pyproject_toml()
err_msg = e.value.args[0]
assert "contains an invalid requirement" in err_msg