Skip to content

Commit

Permalink
add new test build with output option
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-callonnec authored and bcallonnec committed Jan 29, 2024
1 parent 1d8e2eb commit 3947445
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
4 changes: 0 additions & 4 deletions src/poetry/console/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
from poetry.utils.env import build_environment


if TYPE_CHECKING:
from pathlib import Path


class BuildCommand(EnvCommand):
name = "build"
description = "Builds a package, as a tarball and a wheel by default."
Expand Down
37 changes: 26 additions & 11 deletions tests/console/commands/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,16 @@ def test_build_with_multiple_readme_files(
tmp_path: Path,
tmp_venv: VirtualEnv,
command_tester_factory: CommandTesterFactory,
output_dir: str,
) -> None:
source_dir = fixture_dir("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()

if output_dir is None:
tester.execute()
build_dir = target_dir / "dist"
elif output_dir == "absolute":
tester.execute(f"--output {target_dir / 'tmp/dist'}")
build_dir = target_dir / "tmp/dist"
else:
tester.execute(f"--output {output_dir}")
build_dir = target_dir / output_dir

build_dir = target_dir / "dist"
assert build_dir.exists()

sdist_file = build_dir / "my_package-0.1.tar.gz"
Expand All @@ -101,3 +92,27 @@ def test_build_with_multiple_readme_files(

assert "my_package-0.1/README-1.rst" in sdist_content
assert "my_package-0.1/README-2.rst" in sdist_content


@pytest.mark.parametrize(
"output_dir", [None, "dist", "test/dir", "../dist", "absolute"]
)
def test_build_output_option(
tmp_tester: CommandTester,
tmp_project_path: Path,
tmp_poetry: Poetry,
output_dir: str,
) -> None:
if output_dir is None:
tmp_tester.execute()
build_dir = tmp_project_path / "dist"
elif output_dir == "absolute":
tmp_tester.execute(f"--output {tmp_project_path / 'tmp/dist'}")
build_dir = tmp_project_path / "tmp/dist"
else:
tmp_tester.execute(f"--output {output_dir}")
build_dir = tmp_project_path / output_dir

build_artifacts = tuple(build_dir.glob(get_package_glob(tmp_poetry)))
assert len(build_artifacts) > 0
assert all(archive.exists() for archive in build_artifacts)

0 comments on commit 3947445

Please sign in to comment.