-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Copy pathtest_remove_plugins.py
107 lines (77 loc) · 2.94 KB
/
test_remove_plugins.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from __future__ import annotations
from typing import TYPE_CHECKING
import pytest
import tomlkit
from poetry.core.packages.dependency import Dependency
from poetry.core.packages.package import Package
from poetry.core.packages.project_package import ProjectPackage
from poetry.__version__ import __version__
from poetry.console.commands.self.self_command import SelfCommand
from poetry.factory import Factory
from tests.console.commands.self.utils import get_self_command_dependencies
if TYPE_CHECKING:
from cleo.testers.command_tester import CommandTester
from poetry.repositories import Repository
from tests.types import CommandTesterFactory
@pytest.fixture()
def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
return command_tester_factory("self remove")
@pytest.fixture(autouse=True)
def install_plugin(installed: Repository) -> None:
package = ProjectPackage("poetry-instance", __version__)
plugin = Package("poetry-plugin", "1.2.3")
package.add_dependency(
Dependency(plugin.name, "^1.2.3", groups=[SelfCommand.ADDITIONAL_PACKAGE_GROUP])
)
content = Factory.create_pyproject_from_package(package)
system_pyproject_file = SelfCommand.get_default_system_pyproject_file()
system_pyproject_file.write_text(content.as_string(), encoding="utf-8")
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",
"files": {"poetry-plugin": []},
},
}
system_pyproject_file.parent.joinpath("poetry.lock").write_text(
tomlkit.dumps(lock_content), encoding="utf-8"
)
installed.add_package(plugin)
def test_remove_installed_package(tester: CommandTester):
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
dependencies = get_self_command_dependencies()
assert "poetry-plugin" not in dependencies
assert not dependencies
def test_remove_installed_package_dry_run(tester: CommandTester):
tester.execute("poetry-plugin --dry-run")
expected = f"""\
Updating dependencies
Resolving dependencies...
Package operations: 0 installs, 0 updates, 1 removal, 1 skipped
• Removing poetry-plugin (1.2.3)
• Installing poetry ({__version__}): Skipped for the following reason: Already \
installed
"""
assert tester.io.fetch_output() == expected
dependencies = get_self_command_dependencies()
assert "poetry-plugin" in dependencies