Added unit tests for use_pep517 flag

This commit is contained in:
Paul Moore 2018-07-27 14:31:26 +01:00
parent c5a6843c08
commit 73a5847b26
6 changed files with 55 additions and 1 deletions

View File

@ -614,7 +614,10 @@ class InstallRequirement(object):
if self.use_pep517 is False:
raise InstallationError(
"Disabling PEP 517 processing is invalid: "
"project specifies a build-backend in pyproject.toml"
"project specifies a build backend of {} "
"in pyproject.toml".format(
build_system["build-backend"]
)
)
self.use_pep517 = True

View File

@ -0,0 +1,3 @@
[build-system]
requires = ["foo"]
build-backend = "foo"

View File

@ -0,0 +1,3 @@
[build-system]
requires = ["foo"]
build-backend = "foo"

View File

@ -0,0 +1,2 @@
from setuptools import setup
setup(name="dummy", version="0.1")

View File

@ -0,0 +1,2 @@
from setuptools import setup
setup(name="dummy", version="0.1")

41
tests/unit/test_pep517.py Normal file
View File

@ -0,0 +1,41 @@
import pytest
from pip._internal.exceptions import InstallationError
from pip._internal.req import InstallRequirement
@pytest.mark.parametrize(('source', 'expected'), [
("pep517_setup_and_pyproject", True),
("pep517_setup_only", False),
("pep517_pyproject_only", True),
])
def test_use_pep517(data, source, expected):
"""
Test that we choose correctly between PEP 517 and legacy code paths
"""
src = data.src.join(source)
req = InstallRequirement(None, None, source_dir=src)
req.load_pyproject_toml()
assert req.use_pep517 is expected
@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(data, source, msg):
"""
Test that we fail if we try to disable PEP 517 when it's not acceptable
"""
src = data.src.join(source)
req = InstallRequirement(None, None, source_dir=src)
# 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