Commit 98568d49 by Wagner Macedo Committed by GitHub

Add tests for pyproject with multiple readme files (#6678)

parent 651d82db
from __future__ import annotations
import shutil
import tarfile
from pathlib import Path
from typing import TYPE_CHECKING
from poetry.factory import Factory
if TYPE_CHECKING:
from poetry.utils.env import VirtualEnv
from tests.types import CommandTesterFactory
def test_build_with_multiple_readme_files(
tmp_path: Path, tmp_venv: VirtualEnv, command_tester_factory: CommandTesterFactory
):
source_dir = (
Path(__file__).parent.parent.parent / "fixtures" / "with_multiple_readme_files"
)
target_dir = tmp_path / "project"
shutil.copytree(str(source_dir), str(target_dir))
poetry = Factory().create_poetry(target_dir)
tester = command_tester_factory("build", poetry, environment=tmp_venv)
tester.execute()
build_dir = target_dir / "dist"
assert build_dir.exists()
sdist_file = build_dir / "my_package-0.1.tar.gz"
assert sdist_file.exists()
assert sdist_file.stat().st_size > 0
(wheel_file,) = build_dir.glob("my_package-0.1-*.whl")
assert wheel_file.exists()
assert wheel_file.stat().st_size > 0
sdist_content = tarfile.open(sdist_file).getnames()
assert "my_package-0.1/README-1.rst" in sdist_content
assert "my_package-0.1/README-2.rst" in sdist_content
"""Example module"""
from __future__ import annotations
__version__ = "0.1"
[tool.poetry]
name = "my-package"
version = "0.1"
description = "Some description."
authors = [
"Your Name <you@example.com>"
]
license = "MIT"
readme = [
"README-1.rst",
"README-2.rst"
]
homepage = "https://python-poetry.org"
[tool.poetry.dependencies]
python = "^2.7"
...@@ -68,6 +68,15 @@ def extended_without_setup_poetry() -> Poetry: ...@@ -68,6 +68,15 @@ def extended_without_setup_poetry() -> Poetry:
return poetry return poetry
@pytest.fixture
def with_multiple_readme_files() -> Poetry:
poetry = Factory().create_poetry(
Path(__file__).parent.parent.parent / "fixtures" / "with_multiple_readme_files"
)
return poetry
@pytest.fixture() @pytest.fixture()
def env_manager(simple_poetry: Poetry) -> EnvManager: def env_manager(simple_poetry: Poetry) -> EnvManager:
return EnvManager(simple_poetry) return EnvManager(simple_poetry)
...@@ -287,6 +296,44 @@ def test_builder_installs_proper_files_when_packages_configured( ...@@ -287,6 +296,44 @@ def test_builder_installs_proper_files_when_packages_configured(
assert len(paths) == len(expected) assert len(paths) == len(expected)
def test_builder_generates_proper_metadata_when_multiple_readme_files(
with_multiple_readme_files: Poetry, tmp_venv: VirtualEnv
):
builder = EditableBuilder(with_multiple_readme_files, tmp_venv, NullIO())
builder.build()
dist_info = "my_package-0.1.dist-info"
assert tmp_venv.site_packages.exists(dist_info)
dist_info = tmp_venv.site_packages.find(dist_info)[0]
assert dist_info.joinpath("METADATA").exists()
metadata = """\
Metadata-Version: 2.1
Name: my-package
Version: 0.1
Summary: Some description.
Home-page: https://python-poetry.org
License: MIT
Author: Your Name
Author-email: you@example.com
Requires-Python: >=2.7,<3.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Description-Content-Type: text/x-rst
Single Python
=============
Changelog
=========
"""
assert dist_info.joinpath("METADATA").read_text(encoding="utf-8") == metadata
def test_builder_should_execute_build_scripts( def test_builder_should_execute_build_scripts(
mocker: MockerFixture, extended_without_setup_poetry: Poetry, tmp_path: Path mocker: MockerFixture, extended_without_setup_poetry: Poetry, tmp_path: Path
): ):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment