Skip to content

Commit 6676437

Browse files
committed
fix(check): don't raise error on pypi reference
1 parent 6d6971e commit 6676437

File tree

6 files changed

+114
-6
lines changed

6 files changed

+114
-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: 66 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,55 @@ 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("--lock")
141+
fastjsonschema_error = "data must contain ['description'] properties"
142+
custom_error = "The fields ['description'] are required in package mode."
143+
expected_template = """\
144+
Error: Project name (invalid) is same as one of its dependencies
145+
Error: Unrecognized classifiers: ['Intended Audience :: Clowns'].
146+
Error: Declared README file does not exist: never/exists.md
147+
Error: Invalid source "exists" referenced in dependencies.
148+
Error: Invalid source "not-exists" referenced in dependencies.
149+
Error: Invalid source "not-exists2" referenced in dependencies.
150+
Error: poetry.lock was not found.
151+
Warning: A wildcard Python dependency is ambiguous.\
152+
Consider specifying a more explicit one.
153+
Warning: The "pendulum" dependency specifies the "allows-prereleases" property,\
154+
which is deprecated. Use "allow-prereleases" instead.
155+
Warning: Deprecated classifier 'Natural Language :: Ukranian'.\
156+
Must be replaced by ['Natural Language :: Ukrainian'].
157+
Warning: Deprecated classifier\
158+
'Topic :: Communications :: Chat :: AOL Instant Messenger'.\
159+
Must be removed.
160+
"""
161+
expected = {
162+
expected_template.format(schema_error=schema_error)
163+
for schema_error in (fastjsonschema_error, custom_error)
164+
}
165+
166+
assert tester.io.fetch_error() in expected
122167

168+
169+
def test_check_invalid(
170+
tester: CommandTester,
171+
fixture_dir: FixtureDirGetter,
172+
command_tester_factory: CommandTesterFactory,
173+
poetry_with_invalid_pyproject: Poetry,
174+
) -> None:
175+
tester = command_tester_factory("check", poetry=poetry_with_invalid_pyproject)
123176
tester.execute("--lock")
124177

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

255307
# exit with an error
256308
assert status_code == 0
309+
310+
311+
def test_check_does_not_error_on_pypi_reference(
312+
command_tester_factory: CommandTesterFactory,
313+
poetry_with_pypi_reference: Poetry,
314+
) -> None:
315+
tester = command_tester_factory("check", poetry=poetry_with_pypi_reference)
316+
status_code = tester.execute("")
317+
318+
assert tester.io.fetch_output() == "All set!\n"
319+
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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[project]
2+
name = "invalid"
3+
version = "1.0.0"
4+
license = { text = "INVALID" }
5+
classifiers = [
6+
"Environment :: Console",
7+
"Intended Audience :: Clowns",
8+
"Natural Language :: Ukranian",
9+
"Topic :: Communications :: Chat :: AOL Instant Messenger",
10+
]
11+
dynamic = [ "readme", "dependencies", "requires-python" ]
12+
13+
[tool.poetry]
14+
readme = "never/exists.md"
15+
16+
[tool.poetry.dependencies]
17+
python = "*"
18+
pendulum = {"version" = "^2.0.5", allows-prereleases = true}
19+
invalid = "1.0"
20+
invalid_source = { "version" = "*", source = "not-exists" }
21+
invalid_source_multi = [
22+
{ "version" = "*", platform = "linux", source = "exists" },
23+
{ "version" = "*", platform = "win32", source = "not-exists2" },
24+
]
25+
26+
[[tool.poetry.source]]
27+
name = "exists"
28+
priority = "explicit"
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)