diff --git a/src/poetry/console/commands/check.py b/src/poetry/console/commands/check.py index bd672409a81..d6b6517d616 100644 --- a/src/poetry/console/commands/check.py +++ b/src/poetry/console/commands/check.py @@ -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]]] diff --git a/tests/console/commands/test_check.py b/tests/console/commands/test_check.py index 5d0b0226d8d..ed71d7f60e6 100644 --- a/tests/console/commands/test_check.py +++ b/tests/console/commands/test_check.py @@ -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 @@ -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. @@ -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 diff --git a/tests/fixtures/invalid_pyproject/pyproject.toml b/tests/fixtures/invalid_pyproject/pyproject.toml index b830211ac6e..036c5a4aba0 100644 --- a/tests/fixtures/invalid_pyproject/pyproject.toml +++ b/tests/fixtures/invalid_pyproject/pyproject.toml @@ -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" }, @@ -26,3 +26,4 @@ invalid_source_multi = [ [[tool.poetry.source]] name = "exists" priority = "explicit" +url = "https://example.com" diff --git a/tests/fixtures/invalid_pyproject_dep_name/pyproject.toml b/tests/fixtures/invalid_pyproject_dep_name/pyproject.toml new file mode 100644 index 00000000000..2f75face1d9 --- /dev/null +++ b/tests/fixtures/invalid_pyproject_dep_name/pyproject.toml @@ -0,0 +1,7 @@ +[project] +name = "invalid" +version = "1.0.0" +dynamic = ["dependencies"] + +[tool.poetry.dependencies] +invalid = "1.0" diff --git a/tests/fixtures/pypi_reference/pyproject.toml b/tests/fixtures/pypi_reference/pyproject.toml new file mode 100644 index 00000000000..09e4872eb56 --- /dev/null +++ b/tests/fixtures/pypi_reference/pyproject.toml @@ -0,0 +1,16 @@ +[project] +name = "foobar" +version = "0.1.0" +description = "" +authors = [ + { name = "Poetry Developer", email = "" } +] +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" diff --git a/tests/test_factory.py b/tests/test_factory.py index ddd4ae657a4..215f5171b20 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -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: