Skip to content

Commit

Permalink
fix(check): don't raise error on pypi reference (python-poetry#9475)
Browse files Browse the repository at this point in the history
Co-authored-by: Randy Döring <[email protected]>
  • Loading branch information
Secrus and radoering authored Dec 3, 2024
1 parent 9e2a8bd commit bd4adcb
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/poetry/console/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _validate_readme(self, readme: str | list[str], poetry_file: Path) -> list[s

def _validate_dependencies_source(self, config: dict[str, Any]) -> list[str]:
"""Check dependencies's source are valid"""
sources = {k["name"] for k in config.get("source", [])}
sources = {repository.name for repository in self.poetry.pool.all_repositories}

dependency_declarations: list[
dict[str, str | dict[str, str] | list[dict[str, str]]]
Expand Down
49 changes: 46 additions & 3 deletions tests/console/commands/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ def poetry_with_up_to_date_lockfile(
yield Factory().create_poetry(cwd)


@pytest.fixture
def poetry_with_pypi_reference(
set_project_context: SetProjectContext,
) -> Iterator[Poetry]:
with set_project_context("pypi_reference", in_place=False) as cwd:
yield Factory().create_poetry(cwd)


@pytest.fixture
def poetry_with_invalid_pyproject(
set_project_context: SetProjectContext,
) -> Iterator[Poetry]:
with set_project_context("invalid_pyproject", in_place=False) as cwd:
yield Factory().create_poetry(cwd)


@pytest.fixture()
def tester(
command_tester_factory: CommandTesterFactory, poetry_simple_project: Poetry
Expand Down Expand Up @@ -111,19 +127,35 @@ def test_check_valid_legacy(
assert tester.io.fetch_error() == expected


def test_check_invalid(
def test_check_invalid_dep_name_same_as_project_name(
mocker: MockerFixture, tester: CommandTester, fixture_dir: FixtureDirGetter
) -> None:
mocker.patch(
"poetry.poetry.Poetry.file",
return_value=TOMLFile(fixture_dir("invalid_pyproject") / "pyproject.toml"),
return_value=TOMLFile(
fixture_dir("invalid_pyproject_dep_name") / "pyproject.toml"
),
new_callable=mocker.PropertyMock,
)
tester.execute("")

expected = """\
Error: Project name (invalid) is same as one of its dependencies
"""

assert tester.io.fetch_error() == expected


def test_check_invalid(
tester: CommandTester,
fixture_dir: FixtureDirGetter,
command_tester_factory: CommandTesterFactory,
poetry_with_invalid_pyproject: Poetry,
) -> None:
tester = command_tester_factory("check", poetry=poetry_with_invalid_pyproject)
tester.execute("--lock")

expected = """\
Error: Project name (invalid) is same as one of its dependencies
Error: Unrecognized classifiers: ['Intended Audience :: Clowns'].
Error: Declared README file does not exist: never/exists.md
Error: Invalid source "not-exists" referenced in dependencies.
Expand Down Expand Up @@ -254,3 +286,14 @@ def test_check_lock_up_to_date(

# exit with an error
assert status_code == 0


def test_check_does_not_error_on_pypi_reference(
command_tester_factory: CommandTesterFactory,
poetry_with_pypi_reference: Poetry,
) -> None:
tester = command_tester_factory("check", poetry=poetry_with_pypi_reference)
status_code = tester.execute("")

assert tester.io.fetch_output() == "All set!\n"
assert status_code == 0
3 changes: 2 additions & 1 deletion tests/fixtures/invalid_pyproject/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ readme = "never/exists.md"
[tool.poetry.dependencies]
python = "*"
pendulum = {"version" = "^2.0.5", allows-prereleases = true}
invalid = "1.0"
invalid_dep = "1.0"
invalid_source = { "version" = "*", source = "not-exists" }
invalid_source_multi = [
{ "version" = "*", platform = "linux", source = "exists" },
Expand All @@ -26,3 +26,4 @@ invalid_source_multi = [
[[tool.poetry.source]]
name = "exists"
priority = "explicit"
url = "https://example.com"
7 changes: 7 additions & 0 deletions tests/fixtures/invalid_pyproject_dep_name/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[project]
name = "invalid"
version = "1.0.0"
dynamic = ["dependencies"]

[tool.poetry.dependencies]
invalid = "1.0"
16 changes: 16 additions & 0 deletions tests/fixtures/pypi_reference/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[project]
name = "foobar"
version = "0.1.0"
description = ""
authors = [
{ name = "Poetry Developer", email = "<[email protected]>" }
]
dynamic = ["dependencies", "requires-python"]

[tool.poetry.dependencies]
python = "^3.8"
docker = { version = ">=4.3.1", source = "PyPI" }

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
2 changes: 1 addition & 1 deletion tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def test_create_poetry_fails_on_invalid_configuration(
fixture_dir: FixtureDirGetter,
) -> None:
with pytest.raises(RuntimeError) as e:
Factory().create_poetry(fixture_dir("invalid_pyproject"))
Factory().create_poetry(fixture_dir("invalid_pyproject_dep_name"))

expected = """\
The Poetry configuration is invalid:
Expand Down

0 comments on commit bd4adcb

Please sign in to comment.