Skip to content

Commit

Permalink
test: add integration test using repository poetry-core as backend
Browse files Browse the repository at this point in the history
  • Loading branch information
mkniewallner authored Oct 12, 2022
1 parent 8410e35 commit 775d8e3
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/fixtures/pep_517_backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This fixture allows testing a project that uses the repository version of `poetry-core`
as a PEP 517 backend.
Empty file.
37 changes: 37 additions & 0 deletions tests/fixtures/pep_517_backend/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[tool.poetry]
name = "foo"
version = "1.2.3"
description = "Some description."
authors = ["Foo <foo@bar.com>"]
license = "MIT"
readme = "README.md"

homepage = "https://example.com"
repository = "https://github.com/example/example"
documentation = "https://example.com"

keywords = ["example", "packaging"]

classifiers = [
"Topic :: Software Development :: Build Tools",
"Topic :: Software Development :: Libraries :: Python Modules"
]

[tool.poetry.dependencies]
python = "^3.7"
attrs = "^22.1.0"

[tool.poetry.group.dev.dependencies]
pytest = "7.1.3"

# Non-regression test for https://github.com/python-poetry/poetry-core/pull/492.
# The underlying issue occurred because `tomlkit` can either return a TOML table as `Table` instance or an
# `OutOfOrderProxy` one, if a table is discontinuous and multiple sections of a table are separated by a non-related
# table, but we were too strict in our type check assertions.
# So adding `tool.black` here ensure that we have discontinuous tables, so that we don't re-introduce the issue caused
# by the type check assertion that ended up being reverted.
[tool.black]
preview = true

[tool.poetry.scripts]
my-script = "my_package:main"
9 changes: 9 additions & 0 deletions tests/fixtures/sample_project/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ dataclasses = {version = "^0.7", python = ">=3.6.1,<3.7"}
[tool.poetry.extras]
db = [ "orator" ]

# Non-regression test for https://github.com/python-poetry/poetry-core/pull/492.
# The underlying issue occurred because `tomlkit` can either return a TOML table as `Table` instance or an
# `OutOfOrderProxy` one, if a table is discontinuous and multiple sections of a table are separated by a non-related
# table, but we were too strict in our type check assertions.
# So adding `tool.black` here ensure that we have discontinuous tables, so that we don't re-introduce the issue caused
# by the type check assertion that ended up being reverted.
[tool.black]
preview = true

[tool.poetry.group.dev.dependencies]
pytest = "~3.4"

Expand Down
54 changes: 54 additions & 0 deletions tests/integration/test_pep517_backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from __future__ import annotations

import shutil

from pathlib import Path

import pytest

from tests.testutils import subprocess_run


pytestmark = pytest.mark.integration


BUILD_SYSTEM_TEMPLATE = """
[build-system]
requires = ["poetry-core @ file://{project_path}"]
build-backend = "poetry.core.masonry.api"
"""


def test_pip_install(
temporary_directory: Path, project_source_root: Path, python: str
) -> None:
"""
Ensure that a project using the repository version of poetry-core as a PEP 517 backend can be built.
"""
temp_pep_517_backend_path = temporary_directory / "pep_517_backend"

# Copy `pep_517_backend` to a temporary directory as we need to dynamically add the
# build system during the test. This ensures that we don't update the source, since
# the value of `requires` is dynamic.
shutil.copytree(
Path(__file__).parent.parent / "fixtures/pep_517_backend",
temp_pep_517_backend_path,
)

# Append dynamic `build-system` section to `pyproject.toml` in the temporary
# project directory.
with open(temp_pep_517_backend_path / "pyproject.toml", "a") as f:
f.write(
BUILD_SYSTEM_TEMPLATE.format(project_path=project_source_root.as_posix())
)

subprocess_run(
python,
"-m",
"pip",
"install",
temp_pep_517_backend_path.as_posix(),
)

pip_show = subprocess_run(python, "-m", "pip", "show", "foo")
assert "Name: foo" in pip_show.stdout

0 comments on commit 775d8e3

Please sign in to comment.