Skip to content

Commit

Permalink
tests: improve integration coverage for pep517
Browse files Browse the repository at this point in the history
This change adds coverage for the following.
- pip wheel build
- pep517 compliance checks
- pep517 builds for sdists and wheels
- pip install with --no-binary :all:
  • Loading branch information
abn committed Apr 18, 2020
1 parent 2dcd6ab commit 5f2a672
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 9 deletions.
33 changes: 25 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

from poetry.core.utils._compat import Path
from tests.utils import tempfile


def pytest_addoption(parser):
Expand Down Expand Up @@ -32,23 +33,39 @@ def get(name): # type: (str) -> Path
return get


@pytest.fixture
def common_fixtures_directory(): # type: () -> Path
return Path(__file__).parent / "fixtures"
@pytest.fixture(scope="session")
def project_source_root(): # type: () -> Path
return Path(__file__).parent.parent


@pytest.fixture
@pytest.fixture(scope="session")
def project_source_test_root(): # type: () -> Path
return Path(__file__).parent


@pytest.fixture(scope="session")
def common_fixtures_directory(project_source_test_root): # type: (Path) -> Path
return project_source_test_root / "fixtures"


@pytest.fixture(scope="session")
def common_project(common_fixtures_directory): # type: (Path) -> Callable[[str], Path]
return get_project_from_dir(common_fixtures_directory)


@pytest.fixture
def masonry_fixtures_directory(): # type: () -> Path
return Path(__file__).parent / "masonry" / "builders" / "fixtures"
@pytest.fixture(scope="session")
def masonry_fixtures_directory(project_source_test_root): # type: (Path) -> Path
return project_source_test_root / "masonry" / "builders" / "fixtures"


@pytest.fixture
@pytest.fixture(scope="session")
def masonry_project(
masonry_fixtures_directory,
): # type: (Path) -> Callable[[str], Path]
return get_project_from_dir(masonry_fixtures_directory)


@pytest.fixture
def temporary_directory(): # type: () -> Path
with tempfile.TemporaryDirectory(prefix="poetry-core") as tmp:
yield Path(tmp)
63 changes: 62 additions & 1 deletion tests/integration/test_pep517.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import sys

from pathlib import Path

import pytest

from pep517.build import build
from pep517.check import check
from poetry.core.utils._compat import PY35
from tests.utils import subprocess_run
from tests.utils import temporary_project_directory


Expand All @@ -15,6 +22,60 @@
("masonry_project", "disable_setup_py"),
],
)
def test_pep517_check(request, getter, project):
def test_pep517_check_poetry_managed(request, getter, project):
with temporary_project_directory(request.getfixturevalue(getter)(project)) as path:
assert check(path)


def test_pep517_check(project_source_root):
assert check(str(project_source_root))


def test_pep517_build_sdist(temporary_directory, project_source_root):
build(
source_dir=str(project_source_root), dist="sdist", dest=str(temporary_directory)
)
distributions = list(temporary_directory.glob("poetry-core-*.tar.gz"))
assert len(distributions) == 1


def test_pep517_build_wheel(temporary_directory, project_source_root):
build(
source_dir=str(project_source_root), dist="wheel", dest=str(temporary_directory)
)
distributions = list(temporary_directory.glob("poetry_core-*-none-any.whl"))
assert len(distributions) == 1


def test_pip_wheel_build(temporary_directory, project_source_root):
tmp = str(temporary_directory)
pip = subprocess_run(
"pip", "wheel", "--use-pep517", "-w", tmp, str(project_source_root)
)
assert "Successfully built poetry-core" in pip.stdout

assert pip.returncode == 0

wheels = list(Path(tmp).glob("poetry_core-*-none-any.whl"))
assert len(wheels) == 1


@pytest.mark.skipif(not PY35, reason="This test uses the python built-in venv module.")
def test_pip_install_no_binary(temporary_directory, project_source_root):
venv_dir = temporary_directory / ".venv"
venv_python = venv_dir / "bin" / "python"

subprocess_run(sys.executable, "-m", "venv", str(venv_dir))
subprocess_run(str(venv_python), "-m", "pip", "install", "--upgrade", "pip")
subprocess_run(
str(venv_python),
"-m",
"pip",
"install",
"--no-binary",
":all:",
str(project_source_root),
)

pip_show = subprocess_run(str(venv_python), "-m", "pip", "show", "poetry-core")
assert "Name: poetry-core" in pip_show.stdout
12 changes: 12 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import shutil
import subprocess

from contextlib import contextmanager
from typing import Any
Expand Down Expand Up @@ -50,3 +51,14 @@ def temporary_project_directory(
data.update(toml_patch or __toml_build_backend_patch__)
toml.write(data)
yield str(dst)


def subprocess_run(*args, **kwargs): # type: (str, Any) -> subprocess.CompletedProcess
"""
Helper method to run a subprocess. Asserts for success.
"""
result = subprocess.run(
args, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs
)
assert result.returncode == 0
return result

0 comments on commit 5f2a672

Please sign in to comment.