Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions tests/console/commands/test_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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
2 changes: 2 additions & 0 deletions tests/fixtures/with_multiple_readme_files/README-1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Single Python
=============
2 changes: 2 additions & 0 deletions tests/fixtures/with_multiple_readme_files/README-2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Changelog
=========
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Example module"""

from __future__ import annotations


__version__ = "0.1"
19 changes: 19 additions & 0 deletions tests/fixtures/with_multiple_readme_files/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[tool.poetry]
name = "my-package"
version = "0.1"
description = "Some description."
authors = [
"Your Name <[email protected]>"
]
license = "MIT"

readme = [
"README-1.rst",
"README-2.rst"
]

homepage = "https://python-poetry.org"


[tool.poetry.dependencies]
python = "^2.7"
47 changes: 47 additions & 0 deletions tests/masonry/builders/test_editable_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ def extended_without_setup_poetry() -> 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()
def env_manager(simple_poetry: Poetry) -> EnvManager:
return EnvManager(simple_poetry)
Expand Down Expand Up @@ -287,6 +296,44 @@ def test_builder_installs_proper_files_when_packages_configured(
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: [email protected]
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(
mocker: MockerFixture, extended_without_setup_poetry: Poetry, tmp_path: Path
):
Expand Down