Skip to content

Commit bd4adcb

Browse files
Secrusradoering
andauthored
fix(check): don't raise error on pypi reference (#9475)
Co-authored-by: Randy Döring <[email protected]>
1 parent 9e2a8bd commit bd4adcb

File tree

6 files changed

+73
-6
lines changed

6 files changed

+73
-6
lines changed

src/poetry/console/commands/check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def _validate_readme(self, readme: str | list[str], poetry_file: Path) -> list[s
9494

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

9999
dependency_declarations: list[
100100
dict[str, str | dict[str, str] | list[dict[str, str]]]

tests/console/commands/test_check.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ def poetry_with_up_to_date_lockfile(
4343
yield Factory().create_poetry(cwd)
4444

4545

46+
@pytest.fixture
47+
def poetry_with_pypi_reference(
48+
set_project_context: SetProjectContext,
49+
) -> Iterator[Poetry]:
50+
with set_project_context("pypi_reference", in_place=False) as cwd:
51+
yield Factory().create_poetry(cwd)
52+
53+
54+
@pytest.fixture
55+
def poetry_with_invalid_pyproject(
56+
set_project_context: SetProjectContext,
57+
) -> Iterator[Poetry]:
58+
with set_project_context("invalid_pyproject", in_place=False) as cwd:
59+
yield Factory().create_poetry(cwd)
60+
61+
4662
@pytest.fixture()
4763
def tester(
4864
command_tester_factory: CommandTesterFactory, poetry_simple_project: Poetry
@@ -111,19 +127,35 @@ def test_check_valid_legacy(
111127
assert tester.io.fetch_error() == expected
112128

113129

114-
def test_check_invalid(
130+
def test_check_invalid_dep_name_same_as_project_name(
115131
mocker: MockerFixture, tester: CommandTester, fixture_dir: FixtureDirGetter
116132
) -> None:
117133
mocker.patch(
118134
"poetry.poetry.Poetry.file",
119-
return_value=TOMLFile(fixture_dir("invalid_pyproject") / "pyproject.toml"),
135+
return_value=TOMLFile(
136+
fixture_dir("invalid_pyproject_dep_name") / "pyproject.toml"
137+
),
120138
new_callable=mocker.PropertyMock,
121139
)
140+
tester.execute("")
141+
142+
expected = """\
143+
Error: Project name (invalid) is same as one of its dependencies
144+
"""
145+
146+
assert tester.io.fetch_error() == expected
147+
122148

149+
def test_check_invalid(
150+
tester: CommandTester,
151+
fixture_dir: FixtureDirGetter,
152+
command_tester_factory: CommandTesterFactory,
153+
poetry_with_invalid_pyproject: Poetry,
154+
) -> None:
155+
tester = command_tester_factory("check", poetry=poetry_with_invalid_pyproject)
123156
tester.execute("--lock")
124157

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

255287
# exit with an error
256288
assert status_code == 0
289+
290+
291+
def test_check_does_not_error_on_pypi_reference(
292+
command_tester_factory: CommandTesterFactory,
293+
poetry_with_pypi_reference: Poetry,
294+
) -> None:
295+
tester = command_tester_factory("check", poetry=poetry_with_pypi_reference)
296+
status_code = tester.execute("")
297+
298+
assert tester.io.fetch_output() == "All set!\n"
299+
assert status_code == 0

tests/fixtures/invalid_pyproject/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ readme = "never/exists.md"
1616
[tool.poetry.dependencies]
1717
python = "*"
1818
pendulum = {"version" = "^2.0.5", allows-prereleases = true}
19-
invalid = "1.0"
19+
invalid_dep = "1.0"
2020
invalid_source = { "version" = "*", source = "not-exists" }
2121
invalid_source_multi = [
2222
{ "version" = "*", platform = "linux", source = "exists" },
@@ -26,3 +26,4 @@ invalid_source_multi = [
2626
[[tool.poetry.source]]
2727
name = "exists"
2828
priority = "explicit"
29+
url = "https://example.com"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[project]
2+
name = "invalid"
3+
version = "1.0.0"
4+
dynamic = ["dependencies"]
5+
6+
[tool.poetry.dependencies]
7+
invalid = "1.0"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[project]
2+
name = "foobar"
3+
version = "0.1.0"
4+
description = ""
5+
authors = [
6+
{ name = "Poetry Developer", email = "<[email protected]>" }
7+
]
8+
dynamic = ["dependencies", "requires-python"]
9+
10+
[tool.poetry.dependencies]
11+
python = "^3.8"
12+
docker = { version = ">=4.3.1", source = "PyPI" }
13+
14+
[build-system]
15+
requires = ["poetry-core>=1.0.0"]
16+
build-backend = "poetry.core.masonry.api"

tests/test_factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def test_create_poetry_fails_on_invalid_configuration(
405405
fixture_dir: FixtureDirGetter,
406406
) -> None:
407407
with pytest.raises(RuntimeError) as e:
408-
Factory().create_poetry(fixture_dir("invalid_pyproject"))
408+
Factory().create_poetry(fixture_dir("invalid_pyproject_dep_name"))
409409

410410
expected = """\
411411
The Poetry configuration is invalid:

0 commit comments

Comments
 (0)