Skip to content
Open
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
37 changes: 37 additions & 0 deletions tests/console/commands/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import pytest

from cleo.io.buffered_io import BufferedIO
from cleo.io.null_io import NullIO
from cleo.testers.application_tester import ApplicationTester

Expand Down Expand Up @@ -92,6 +93,28 @@ def test_build_with_local_version_label(

assert len(build_artifacts) > 0
assert all(archive.exists() for archive in build_artifacts)
assert "`--local-version` is deprecated." in tmp_tester.io.fetch_error()


def test_build_with_config_settings_local_version(
tmp_tester: CommandTester, tmp_project_path: Path, tmp_poetry: Poetry
) -> None:
shutil.rmtree(tmp_project_path / "dist")
local_version_label = "local-version"
assert (
tmp_tester.execute(f"--config-settings local-version={local_version_label}")
== 0
)
build_artifacts = tuple(
(tmp_project_path / "dist").glob(
get_package_glob(tmp_poetry, local_version=local_version_label)
)
)

assert len(build_artifacts) > 0
assert all(archive.exists() for archive in build_artifacts)
assert all(local_version_label in archive.name for archive in build_artifacts)
assert "`--local-version` is deprecated." not in tmp_tester.io.fetch_error()
Comment on lines +108 to +117

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Strengthen --config-settings local-version coverage by asserting artifact names include the local version label

This test currently only verifies that some artifacts exist for the glob from get_package_glob, but not that the local version label is actually present in their filenames. If get_package_glob became too permissive, the test could still pass while ignoring the local version. Please add an assertion (e.g. assert all(local_version_label in archive.name for archive in build_artifacts)) to directly verify artifact naming and better protect against regressions.

Suggested implementation:

    assert len(build_artifacts) > 0
    assert all(archive.exists() for archive in build_artifacts)
    assert all(local_version_label in archive.name for archive in build_artifacts)
    assert "`--local-version` is deprecated." in tmp_tester.io.fetch_error()

This change assumes:

  1. build_artifacts is defined earlier in test_build_with_config_settings_local_version as an iterable of artifact paths.
  2. local_version_label is the string used in the --config-settings local-version=... invocation.
    If either name differs in your actual file, please adjust the assertion to match the existing variable names.



@pytest.mark.parametrize("clean", [True, False])
Expand Down Expand Up @@ -285,6 +308,20 @@ def test_requires_isolated_build(
assert handler._requires_isolated_build() is isolated_build


@pytest.mark.parametrize("project", ["no_build_system", "no_build_backend"])
def test_requires_isolated_build_warns_when_no_build_backend(
project: str,
fixture_dir: FixtureDirGetter,
mocker: MockerFixture,
) -> None:
poetry = Factory().create_poetry(fixture_dir(f"build_systems/{project}"))
io = BufferedIO()
handler = BuildHandler(poetry=poetry, env=mocker.Mock(), io=io)

assert handler._requires_isolated_build() is False
assert "No build backend defined" in io.fetch_error()


def test_build_handler_build_isolated(
fixture_dir: FixtureDirGetter, mocker: MockerFixture
) -> None:
Expand Down