|
| 1 | +import pytest |
| 2 | +import tomlkit |
| 3 | + |
| 4 | +from poetry.__version__ import __version__ |
| 5 | +from poetry.core.packages.package import Package |
| 6 | +from poetry.layouts.layout import POETRY_DEFAULT |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture() |
| 10 | +def tester(command_tester_factory): |
| 11 | + return command_tester_factory("plugin remove") |
| 12 | + |
| 13 | + |
| 14 | +@pytest.fixture() |
| 15 | +def pyproject(env): |
| 16 | + pyproject = tomlkit.loads(POETRY_DEFAULT) |
| 17 | + content = pyproject["tool"]["poetry"] |
| 18 | + |
| 19 | + content["name"] = "poetry" |
| 20 | + content["version"] = __version__ |
| 21 | + content["description"] = "" |
| 22 | + content[ "authors"] = [ "Sébastien Eustace <[email protected]>"] |
| 23 | + |
| 24 | + dependency_section = content["dependencies"] |
| 25 | + dependency_section["python"] = "^3.6" |
| 26 | + |
| 27 | + env.path.joinpath("pyproject.toml").write_text( |
| 28 | + tomlkit.dumps(pyproject), encoding="utf-8" |
| 29 | + ) |
| 30 | + |
| 31 | + |
| 32 | +@pytest.fixture(autouse=True) |
| 33 | +def install_plugin(env, installed, pyproject): |
| 34 | + lock_content = { |
| 35 | + "package": [ |
| 36 | + { |
| 37 | + "name": "poetry-plugin", |
| 38 | + "version": "1.2.3", |
| 39 | + "category": "main", |
| 40 | + "optional": False, |
| 41 | + "platform": "*", |
| 42 | + "python-versions": "*", |
| 43 | + "checksum": [], |
| 44 | + }, |
| 45 | + ], |
| 46 | + "metadata": { |
| 47 | + "python-versions": "^3.6", |
| 48 | + "platform": "*", |
| 49 | + "content-hash": "123456789", |
| 50 | + "hashes": {"poetry-plugin": []}, |
| 51 | + }, |
| 52 | + } |
| 53 | + |
| 54 | + env.path.joinpath("poetry.lock").write_text( |
| 55 | + tomlkit.dumps(lock_content), encoding="utf-8" |
| 56 | + ) |
| 57 | + |
| 58 | + pyproject = tomlkit.loads( |
| 59 | + env.path.joinpath("pyproject.toml").read_text(encoding="utf-8") |
| 60 | + ) |
| 61 | + content = pyproject["tool"]["poetry"] |
| 62 | + |
| 63 | + dependency_section = content["dependencies"] |
| 64 | + dependency_section["poetry-plugin"] = "^1.2.3" |
| 65 | + |
| 66 | + env.path.joinpath("pyproject.toml").write_text( |
| 67 | + tomlkit.dumps(pyproject), encoding="utf-8" |
| 68 | + ) |
| 69 | + |
| 70 | + installed.add_package(Package("poetry-plugin", "1.2.3")) |
| 71 | + |
| 72 | + |
| 73 | +def test_remove_installed_package(app, tester, env): |
| 74 | + tester.execute("poetry-plugin") |
| 75 | + |
| 76 | + expected = """\ |
| 77 | +Updating dependencies |
| 78 | +Resolving dependencies... |
| 79 | +
|
| 80 | +Writing lock file |
| 81 | +
|
| 82 | +Package operations: 0 installs, 0 updates, 1 removal |
| 83 | +
|
| 84 | + • Removing poetry-plugin (1.2.3) |
| 85 | +""" |
| 86 | + |
| 87 | + assert tester.io.fetch_output() == expected |
| 88 | + |
| 89 | + remove_command = app.find("remove") |
| 90 | + assert remove_command.poetry.file.parent == env.path |
| 91 | + assert remove_command.poetry.locker.lock.parent == env.path |
| 92 | + assert remove_command.poetry.locker.lock.exists() |
| 93 | + assert not remove_command.installer.executor._dry_run |
| 94 | + |
| 95 | + content = remove_command.poetry.file.read()["tool"]["poetry"] |
| 96 | + assert "poetry-plugin" not in content["dependencies"] |
| 97 | + |
| 98 | + |
| 99 | +def test_remove_installed_package_dry_run(app, tester, env): |
| 100 | + tester.execute("poetry-plugin --dry-run") |
| 101 | + |
| 102 | + expected = """\ |
| 103 | +Updating dependencies |
| 104 | +Resolving dependencies... |
| 105 | +
|
| 106 | +Writing lock file |
| 107 | +
|
| 108 | +Package operations: 0 installs, 0 updates, 1 removal |
| 109 | +
|
| 110 | + • Removing poetry-plugin (1.2.3) |
| 111 | +""" |
| 112 | + |
| 113 | + assert tester.io.fetch_output() == expected |
| 114 | + |
| 115 | + remove_command = app.find("remove") |
| 116 | + assert remove_command.poetry.file.parent == env.path |
| 117 | + assert remove_command.poetry.locker.lock.parent == env.path |
| 118 | + assert remove_command.poetry.locker.lock.exists() |
| 119 | + assert remove_command.installer.executor._dry_run |
| 120 | + |
| 121 | + content = remove_command.poetry.file.read()["tool"]["poetry"] |
| 122 | + assert "poetry-plugin" in content["dependencies"] |
0 commit comments