Skip to content

Commit

Permalink
Add tests and remove unused params for test_add.py (#7899)
Browse files Browse the repository at this point in the history
  • Loading branch information
Savannah Ostrowski authored May 11, 2023
1 parent 905ae95 commit c4e7cc3
Showing 1 changed file with 59 additions and 20 deletions.
79 changes: 59 additions & 20 deletions tests/console/commands/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ def test_add_no_constraint_editable_error(
assert content == pyproject2["tool"]["poetry"]


def test_add_equal_constraint(
app: PoetryTestApplication, repo: TestRepository, tester: CommandTester
) -> None:
def test_add_equal_constraint(repo: TestRepository, tester: CommandTester) -> None:
repo.add_package(get_package("cachy", "0.1.0"))
repo.add_package(get_package("cachy", "0.2.0"))

Expand All @@ -200,9 +198,7 @@ def test_add_equal_constraint(
assert tester.command.installer.executor.installations_count == 1


def test_add_greater_constraint(
app: PoetryTestApplication, repo: TestRepository, tester: CommandTester
) -> None:
def test_add_greater_constraint(repo: TestRepository, tester: CommandTester) -> None:
repo.add_package(get_package("cachy", "0.1.0"))
repo.add_package(get_package("cachy", "0.2.0"))

Expand All @@ -227,7 +223,6 @@ def test_add_greater_constraint(

@pytest.mark.parametrize("extra_name", ["msgpack", "MsgPack"])
def test_add_constraint_with_extras(
app: PoetryTestApplication,
repo: TestRepository,
tester: CommandTester,
extra_name: str,
Expand Down Expand Up @@ -262,7 +257,7 @@ def test_add_constraint_with_extras(


def test_add_constraint_dependencies(
app: PoetryTestApplication, repo: TestRepository, tester: CommandTester
repo: TestRepository, tester: CommandTester
) -> None:
cachy2 = get_package("cachy", "0.2.0")
msgpack_dep = get_dependency("msgpack-python", ">=0.5 <0.6")
Expand Down Expand Up @@ -332,7 +327,6 @@ def test_add_git_constraint(


def test_add_git_constraint_with_poetry(
app: PoetryTestApplication,
repo: TestRepository,
tester: CommandTester,
tmp_venv: VirtualEnv,
Expand Down Expand Up @@ -420,9 +414,7 @@ def test_add_git_constraint_with_subdirectory(
url: str,
rev: str | None,
app: PoetryTestApplication,
repo: TestRepository,
tester: CommandTester,
env: MockEnv,
) -> None:
tester.execute(url)

Expand Down Expand Up @@ -591,7 +583,6 @@ def test_add_file_constraint_wheel(
app: PoetryTestApplication,
repo: TestRepository,
tester: CommandTester,
poetry: Poetry,
) -> None:
repo.add_package(get_package("pendulum", "1.4.4"))

Expand Down Expand Up @@ -755,7 +746,6 @@ def test_add_url_constraint_wheel_with_extras(
repo: TestRepository,
tester: CommandTester,
extra_name: str,
mocker: MockerFixture,
) -> None:
repo.add_package(get_package("pendulum", "1.4.4"))
repo.add_package(get_package("cleo", "0.6.5"))
Expand Down Expand Up @@ -800,6 +790,35 @@ def test_add_url_constraint_wheel_with_extras(
}


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(
app: PoetryTestApplication, repo: TestRepository, tester: CommandTester
) -> None:
Expand Down Expand Up @@ -928,17 +947,14 @@ def test_add_constraint_with_source(
}


def test_add_constraint_with_source_that_does_not_exist(
app: PoetryTestApplication, tester: CommandTester
) -> None:
def test_add_constraint_with_source_that_does_not_exist(tester: CommandTester) -> None:
with pytest.raises(IndexError) as e:
tester.execute("foo --source i-dont-exist")

assert str(e.value) == 'Repository "i-dont-exist" does not exist.'


def test_add_constraint_not_found_with_source(
app: PoetryTestApplication,
poetry: Poetry,
mocker: MockerFixture,
tester: CommandTester,
Expand Down Expand Up @@ -1122,7 +1138,7 @@ def test_add_should_skip_when_adding_canonicalized_existing_package_with_no_cons


def test_add_should_fail_circular_dependency(
app: PoetryTestApplication, repo: TestRepository, tester: CommandTester
repo: TestRepository, tester: CommandTester
) -> None:
repo.add_package(get_package("simple-project", "1.1.2"))
result = tester.execute("simple-project")
Expand Down Expand Up @@ -1206,7 +1222,7 @@ def test_add_should_work_when_adding_existing_package_with_latest_constraint(


def test_add_chooses_prerelease_if_only_prereleases_are_available(
app: PoetryTestApplication, repo: TestRepository, tester: CommandTester
repo: TestRepository, tester: CommandTester
) -> None:
repo.add_package(get_package("foo", "1.2.3b0"))
repo.add_package(get_package("foo", "1.2.3b1"))
Expand All @@ -1229,7 +1245,7 @@ def test_add_chooses_prerelease_if_only_prereleases_are_available(


def test_add_prefers_stable_releases(
app: PoetryTestApplication, repo: TestRepository, tester: CommandTester
repo: TestRepository, tester: CommandTester
) -> None:
repo.add_package(get_package("foo", "1.2.3"))
repo.add_package(get_package("foo", "1.2.4b1"))
Expand Down Expand Up @@ -1467,3 +1483,26 @@ def test_add_extras_are_parsed_and_included(
"version": "^0.2.0",
"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"
)

0 comments on commit c4e7cc3

Please sign in to comment.