Commit 20587f1e by finswimmer Committed by Bjorn Neergaard

replace existing dependency when adding dependency with version constraint

parent ecb030e1
import contextlib
from typing import Dict from typing import Dict
from typing import List from typing import List
...@@ -203,6 +205,12 @@ You can specify a package in the following forms: ...@@ -203,6 +205,12 @@ You can specify a package in the following forms:
constraint = constraint["version"] constraint = constraint["version"]
section[_constraint["name"]] = constraint section[_constraint["name"]] = constraint
with contextlib.suppress(ValueError):
self.poetry.package.dependency_group(group).remove_dependency(
_constraint["name"]
)
self.poetry.package.add_dependency( self.poetry.package.add_dependency(
Factory.create_dependency( Factory.create_dependency(
_constraint["name"], _constraint["name"],
......
...@@ -67,6 +67,53 @@ Package operations: 1 install, 0 updates, 0 removals ...@@ -67,6 +67,53 @@ Package operations: 1 install, 0 updates, 0 removals
assert content["dependencies"]["cachy"] == "^0.2.0" assert content["dependencies"]["cachy"] == "^0.2.0"
def test_add_replace_by_constraint(
app: "PoetryTestApplication", repo: "TestRepository", tester: "CommandTester"
):
repo.add_package(get_package("cachy", "0.1.0"))
repo.add_package(get_package("cachy", "0.2.0"))
tester.execute("cachy")
expected = """\
Using version ^0.2.0 for cachy
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.2.0)
"""
assert tester.io.fetch_output() == expected
assert tester.command.installer.executor.installations_count == 1
content = app.poetry.file.read()["tool"]["poetry"]
assert "cachy" in content["dependencies"]
assert content["dependencies"]["cachy"] == "^0.2.0"
tester.execute("cachy@0.1.0")
expected = """
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.1.0)
"""
assert tester.io.fetch_output() == expected
content = app.poetry.file.read()["tool"]["poetry"]
assert "cachy" in content["dependencies"]
assert content["dependencies"]["cachy"] == "0.1.0"
def test_add_no_constraint_editable_error( def test_add_no_constraint_editable_error(
app: "PoetryTestApplication", repo: "TestRepository", tester: "CommandTester" app: "PoetryTestApplication", repo: "TestRepository", tester: "CommandTester"
): ):
......
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