Skip to content

Commit

Permalink
Executor: Remove duplicate entry with dry-run argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Macchia authored and mmacchia committed Jun 4, 2022
1 parent 53e50d9 commit 12ee359
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/poetry/installation/executor.py
Expand Up @@ -311,8 +311,11 @@ def _do_execute_operation(self, operation: Operation) -> int:
return 0

if not self._enabled or self._dry_run:
<<<<<<< HEAD:src/poetry/installation/executor.py
self._io.write_line(f" <fg=blue;options=bold>•</> {operation_message}")

=======
>>>>>>> 73b6da5e (Executor: Remove duplicate entry with dry-run argument):poetry/installation/executor.py
return 0

result: int = getattr(self, f"_execute_{method}")(operation)
Expand Down Expand Up @@ -713,7 +716,9 @@ def _download_archive(self, operation: Install | Update, link: Link) -> Path:
return archive

def _should_write_operation(self, operation: Operation) -> bool:
return not operation.skipped or self._dry_run or self._verbose
return (
not operation.skipped or self._dry_run or self._verbose or not self._enabled
)

def _save_url_reference(self, operation: Operation) -> None:
"""
Expand Down
122 changes: 122 additions & 0 deletions tests/console/commands/plugin/test_remove.py
@@ -0,0 +1,122 @@
import pytest
import tomlkit

from poetry.__version__ import __version__
from poetry.core.packages.package import Package
from poetry.layouts.layout import POETRY_DEFAULT


@pytest.fixture()
def tester(command_tester_factory):
return command_tester_factory("plugin remove")


@pytest.fixture()
def pyproject(env):
pyproject = tomlkit.loads(POETRY_DEFAULT)
content = pyproject["tool"]["poetry"]

content["name"] = "poetry"
content["version"] = __version__
content["description"] = ""
content["authors"] = ["Sébastien Eustace <sebastien@eustace.io>"]

dependency_section = content["dependencies"]
dependency_section["python"] = "^3.6"

env.path.joinpath("pyproject.toml").write_text(
tomlkit.dumps(pyproject), encoding="utf-8"
)


@pytest.fixture(autouse=True)
def install_plugin(env, installed, pyproject):
lock_content = {
"package": [
{
"name": "poetry-plugin",
"version": "1.2.3",
"category": "main",
"optional": False,
"platform": "*",
"python-versions": "*",
"checksum": [],
},
],
"metadata": {
"python-versions": "^3.6",
"platform": "*",
"content-hash": "123456789",
"hashes": {"poetry-plugin": []},
},
}

env.path.joinpath("poetry.lock").write_text(
tomlkit.dumps(lock_content), encoding="utf-8"
)

pyproject = tomlkit.loads(
env.path.joinpath("pyproject.toml").read_text(encoding="utf-8")
)
content = pyproject["tool"]["poetry"]

dependency_section = content["dependencies"]
dependency_section["poetry-plugin"] = "^1.2.3"

env.path.joinpath("pyproject.toml").write_text(
tomlkit.dumps(pyproject), encoding="utf-8"
)

installed.add_package(Package("poetry-plugin", "1.2.3"))


def test_remove_installed_package(app, tester, env):
tester.execute("poetry-plugin")

expected = """\
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 0 installs, 0 updates, 1 removal
• Removing poetry-plugin (1.2.3)
"""

assert tester.io.fetch_output() == expected

remove_command = app.find("remove")
assert remove_command.poetry.file.parent == env.path
assert remove_command.poetry.locker.lock.parent == env.path
assert remove_command.poetry.locker.lock.exists()
assert not remove_command.installer.executor._dry_run

content = remove_command.poetry.file.read()["tool"]["poetry"]
assert "poetry-plugin" not in content["dependencies"]


def test_remove_installed_package_dry_run(app, tester, env):
tester.execute("poetry-plugin --dry-run")

expected = """\
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 0 installs, 0 updates, 1 removal
• Removing poetry-plugin (1.2.3)
"""

assert tester.io.fetch_output() == expected

remove_command = app.find("remove")
assert remove_command.poetry.file.parent == env.path
assert remove_command.poetry.locker.lock.parent == env.path
assert remove_command.poetry.locker.lock.exists()
assert remove_command.installer.executor._dry_run

content = remove_command.poetry.file.read()["tool"]["poetry"]
assert "poetry-plugin" in content["dependencies"]

0 comments on commit 12ee359

Please sign in to comment.