Commit c4e7cc3e by Savannah Ostrowski Committed by GitHub

Add tests and remove unused params for test_add.py (#7899)

parent 905ae951
...@@ -175,9 +175,7 @@ No changes were applied. ...@@ -175,9 +175,7 @@ No changes were applied.
assert content == pyproject2["tool"]["poetry"] assert content == pyproject2["tool"]["poetry"]
def test_add_equal_constraint( def test_add_equal_constraint(repo: TestRepository, tester: CommandTester) -> None:
app: PoetryTestApplication, repo: TestRepository, tester: CommandTester
) -> None:
repo.add_package(get_package("cachy", "0.1.0")) repo.add_package(get_package("cachy", "0.1.0"))
repo.add_package(get_package("cachy", "0.2.0")) repo.add_package(get_package("cachy", "0.2.0"))
...@@ -200,9 +198,7 @@ Writing lock file ...@@ -200,9 +198,7 @@ Writing lock file
assert tester.command.installer.executor.installations_count == 1 assert tester.command.installer.executor.installations_count == 1
def test_add_greater_constraint( def test_add_greater_constraint(repo: TestRepository, tester: CommandTester) -> None:
app: PoetryTestApplication, repo: TestRepository, tester: CommandTester
) -> None:
repo.add_package(get_package("cachy", "0.1.0")) repo.add_package(get_package("cachy", "0.1.0"))
repo.add_package(get_package("cachy", "0.2.0")) repo.add_package(get_package("cachy", "0.2.0"))
...@@ -227,7 +223,6 @@ Writing lock file ...@@ -227,7 +223,6 @@ Writing lock file
@pytest.mark.parametrize("extra_name", ["msgpack", "MsgPack"]) @pytest.mark.parametrize("extra_name", ["msgpack", "MsgPack"])
def test_add_constraint_with_extras( def test_add_constraint_with_extras(
app: PoetryTestApplication,
repo: TestRepository, repo: TestRepository,
tester: CommandTester, tester: CommandTester,
extra_name: str, extra_name: str,
...@@ -262,7 +257,7 @@ Writing lock file ...@@ -262,7 +257,7 @@ Writing lock file
def test_add_constraint_dependencies( def test_add_constraint_dependencies(
app: PoetryTestApplication, repo: TestRepository, tester: CommandTester repo: TestRepository, tester: CommandTester
) -> None: ) -> None:
cachy2 = get_package("cachy", "0.2.0") cachy2 = get_package("cachy", "0.2.0")
msgpack_dep = get_dependency("msgpack-python", ">=0.5 <0.6") msgpack_dep = get_dependency("msgpack-python", ">=0.5 <0.6")
...@@ -332,7 +327,6 @@ Writing lock file ...@@ -332,7 +327,6 @@ Writing lock file
def test_add_git_constraint_with_poetry( def test_add_git_constraint_with_poetry(
app: PoetryTestApplication,
repo: TestRepository, repo: TestRepository,
tester: CommandTester, tester: CommandTester,
tmp_venv: VirtualEnv, tmp_venv: VirtualEnv,
...@@ -420,9 +414,7 @@ def test_add_git_constraint_with_subdirectory( ...@@ -420,9 +414,7 @@ def test_add_git_constraint_with_subdirectory(
url: str, url: str,
rev: str | None, rev: str | None,
app: PoetryTestApplication, app: PoetryTestApplication,
repo: TestRepository,
tester: CommandTester, tester: CommandTester,
env: MockEnv,
) -> None: ) -> None:
tester.execute(url) tester.execute(url)
...@@ -591,7 +583,6 @@ def test_add_file_constraint_wheel( ...@@ -591,7 +583,6 @@ def test_add_file_constraint_wheel(
app: PoetryTestApplication, app: PoetryTestApplication,
repo: TestRepository, repo: TestRepository,
tester: CommandTester, tester: CommandTester,
poetry: Poetry,
) -> None: ) -> None:
repo.add_package(get_package("pendulum", "1.4.4")) repo.add_package(get_package("pendulum", "1.4.4"))
...@@ -755,7 +746,6 @@ def test_add_url_constraint_wheel_with_extras( ...@@ -755,7 +746,6 @@ def test_add_url_constraint_wheel_with_extras(
repo: TestRepository, repo: TestRepository,
tester: CommandTester, tester: CommandTester,
extra_name: str, extra_name: str,
mocker: MockerFixture,
) -> None: ) -> None:
repo.add_package(get_package("pendulum", "1.4.4")) repo.add_package(get_package("pendulum", "1.4.4"))
repo.add_package(get_package("cleo", "0.6.5")) repo.add_package(get_package("cleo", "0.6.5"))
...@@ -800,6 +790,35 @@ Writing lock file ...@@ -800,6 +790,35 @@ Writing lock file
} }
def test_add_constraint_with_optional(
app: PoetryTestApplication, repo: TestRepository, tester: CommandTester
) -> None:
repo.add_package(get_package("cachy", "0.2.0"))
tester.execute("cachy=0.2.0 --optional")
expected = """\
Updating dependencies
Resolving dependencies...
No dependencies to install or update
Writing lock file
"""
assert tester.io.fetch_output() == expected
assert isinstance(tester.command, InstallerCommand)
assert tester.command.installer.executor.installations_count == 0
pyproject: dict[str, Any] = app.poetry.file.read()
content = pyproject["tool"]["poetry"]
assert "cachy" in content["dependencies"]
assert content["dependencies"]["cachy"] == {
"version": "0.2.0",
"optional": True,
}
def test_add_constraint_with_python( def test_add_constraint_with_python(
app: PoetryTestApplication, repo: TestRepository, tester: CommandTester app: PoetryTestApplication, repo: TestRepository, tester: CommandTester
) -> None: ) -> None:
...@@ -928,9 +947,7 @@ Writing lock file ...@@ -928,9 +947,7 @@ Writing lock file
} }
def test_add_constraint_with_source_that_does_not_exist( def test_add_constraint_with_source_that_does_not_exist(tester: CommandTester) -> None:
app: PoetryTestApplication, tester: CommandTester
) -> None:
with pytest.raises(IndexError) as e: with pytest.raises(IndexError) as e:
tester.execute("foo --source i-dont-exist") tester.execute("foo --source i-dont-exist")
...@@ -938,7 +955,6 @@ def test_add_constraint_with_source_that_does_not_exist( ...@@ -938,7 +955,6 @@ def test_add_constraint_with_source_that_does_not_exist(
def test_add_constraint_not_found_with_source( def test_add_constraint_not_found_with_source(
app: PoetryTestApplication,
poetry: Poetry, poetry: Poetry,
mocker: MockerFixture, mocker: MockerFixture,
tester: CommandTester, tester: CommandTester,
...@@ -1122,7 +1138,7 @@ If you prefer to upgrade it to the latest available version,\ ...@@ -1122,7 +1138,7 @@ If you prefer to upgrade it to the latest available version,\
def test_add_should_fail_circular_dependency( def test_add_should_fail_circular_dependency(
app: PoetryTestApplication, repo: TestRepository, tester: CommandTester repo: TestRepository, tester: CommandTester
) -> None: ) -> None:
repo.add_package(get_package("simple-project", "1.1.2")) repo.add_package(get_package("simple-project", "1.1.2"))
result = tester.execute("simple-project") result = tester.execute("simple-project")
...@@ -1206,7 +1222,7 @@ Writing lock file ...@@ -1206,7 +1222,7 @@ Writing lock file
def test_add_chooses_prerelease_if_only_prereleases_are_available( def test_add_chooses_prerelease_if_only_prereleases_are_available(
app: PoetryTestApplication, repo: TestRepository, tester: CommandTester repo: TestRepository, tester: CommandTester
) -> None: ) -> None:
repo.add_package(get_package("foo", "1.2.3b0")) repo.add_package(get_package("foo", "1.2.3b0"))
repo.add_package(get_package("foo", "1.2.3b1")) repo.add_package(get_package("foo", "1.2.3b1"))
...@@ -1229,7 +1245,7 @@ Writing lock file ...@@ -1229,7 +1245,7 @@ Writing lock file
def test_add_prefers_stable_releases( def test_add_prefers_stable_releases(
app: PoetryTestApplication, repo: TestRepository, tester: CommandTester repo: TestRepository, tester: CommandTester
) -> None: ) -> None:
repo.add_package(get_package("foo", "1.2.3")) repo.add_package(get_package("foo", "1.2.3"))
repo.add_package(get_package("foo", "1.2.4b1")) repo.add_package(get_package("foo", "1.2.4b1"))
...@@ -1467,3 +1483,26 @@ Writing lock file ...@@ -1467,3 +1483,26 @@ Writing lock file
"version": "^0.2.0", "version": "^0.2.0",
"extras": ["redis", "msgpack"], "extras": ["redis", "msgpack"],
} }
@pytest.mark.parametrize(
"command",
[
"requests --extras security socks",
],
)
def test_add_extras_only_accepts_one_package(
command: str, tester: CommandTester, repo: TestRepository
) -> None:
"""
You cannot pass in multiple package values to a single --extras flag.\
e.g. --extras security socks is not allowed.
"""
repo.add_package(get_package("requests", "2.30.0"))
with pytest.raises(ValueError) as e:
tester.execute(command)
assert (
str(e.value)
== "You can only specify one package when using the --extras option"
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment