-
Notifications
You must be signed in to change notification settings - Fork 617
/
Copy pathplugin_management_test.py
150 lines (114 loc) · 4.25 KB
/
plugin_management_test.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import os
import tempfile
from configparser import ConfigParser
from pathlib import Path
import pytest
import errbot.repo_manager
from errbot import plugin_manager
from errbot.plugin_info import PluginInfo
from errbot.plugin_manager import IncompatiblePluginException
from errbot.utils import collect_roots, entry_point_plugins, find_roots
CORE_PLUGINS = plugin_manager.CORE_PLUGINS
def touch(name):
with open(name, "a"):
os.utime(name, None)
assets = Path(__file__).parent / "assets"
def test_check_dependencies():
response, deps = errbot.repo_manager.check_dependencies(
assets / "requirements_never_there.txt"
)
assert "You need these dependencies for" in response
assert "impossible_requirement" in response
assert ["impossible_requirement"] == deps
def test_check_dependencies_no_requirements_file():
response, deps = errbot.repo_manager.check_dependencies(
assets / "requirements_non_existent.txt"
)
assert response is None
def test_check_dependencies_requirements_file_all_installed():
response, deps = errbot.repo_manager.check_dependencies(
assets / "requirements_already_there.txt"
)
assert response is None
def test_find_plugin_roots():
root = tempfile.mkdtemp()
a = os.path.join(root, "a")
b = os.path.join(a, "b")
c = os.path.join(root, "c")
os.mkdir(a)
os.mkdir(b)
os.mkdir(c)
touch(os.path.join(a, "toto.plug"))
touch(os.path.join(b, "titi.plug"))
touch(os.path.join(root, "tutu.plug"))
roots = find_roots(root)
assert root in roots
assert a in roots
assert b in roots
assert c not in roots
def test_collect_roots():
toto = tempfile.mkdtemp()
touch(os.path.join(toto, "toto.plug"))
touch(os.path.join(toto, "titi.plug"))
titi = tempfile.mkdtemp()
touch(os.path.join(titi, "tata.plug"))
tutu = tempfile.mkdtemp()
subtutu = os.path.join(tutu, "subtutu")
os.mkdir(subtutu)
touch(os.path.join(subtutu, "tutu.plug"))
assert collect_roots((CORE_PLUGINS, None)) == [CORE_PLUGINS]
assert collect_roots((CORE_PLUGINS, toto)) == [CORE_PLUGINS, toto]
assert collect_roots((CORE_PLUGINS, [toto, titi])) == [CORE_PLUGINS, toto, titi]
assert collect_roots((CORE_PLUGINS, toto, titi, "nothing")) == [
CORE_PLUGINS,
toto,
titi,
]
assert collect_roots((toto, tutu)) == [toto, subtutu]
def test_ignore_dotted_directories():
root = tempfile.mkdtemp()
a = os.path.join(root, ".invisible")
os.mkdir(a)
touch(os.path.join(a, "toto.plug"))
assert collect_roots((CORE_PLUGINS, root)) == [CORE_PLUGINS]
def dummy_config_parser() -> ConfigParser:
cp = ConfigParser()
cp.add_section("Core")
cp.set("Core", "Name", "dummy")
cp.set("Core", "Module", "dummy")
cp.add_section("Errbot")
return cp
def test_errbot_version_check():
real_version = plugin_manager.VERSION
too_high_min_1 = dummy_config_parser()
too_high_min_1.set("Errbot", "Min", "1.6.0")
too_high_min_2 = dummy_config_parser()
too_high_min_2.set("Errbot", "Min", "1.6.0")
too_high_min_2.set("Errbot", "Max", "2.0.0")
too_low_max_1 = dummy_config_parser()
too_low_max_1.set("Errbot", "Max", "1.0.1-beta")
too_low_max_2 = dummy_config_parser()
too_low_max_2.set("Errbot", "Min", "0.9.0-rc2")
too_low_max_2.set("Errbot", "Max", "1.0.1-beta")
ok1 = dummy_config_parser() # empty section
ok2 = dummy_config_parser()
ok2.set("Errbot", "Min", "1.4.0")
ok3 = dummy_config_parser()
ok3.set("Errbot", "Max", "1.5.2")
ok4 = dummy_config_parser()
ok4.set("Errbot", "Min", "1.2.1")
ok4.set("Errbot", "Max", "1.6.1-rc1")
try:
plugin_manager.VERSION = "1.5.2"
for config in (too_high_min_1, too_high_min_2, too_low_max_1, too_low_max_2):
pi = PluginInfo.parse(config)
with pytest.raises(IncompatiblePluginException):
plugin_manager.check_errbot_version(pi)
for config in (ok1, ok2, ok3, ok4):
pi = PluginInfo.parse(config)
plugin_manager.check_errbot_version(pi)
finally:
plugin_manager.VERSION = real_version
def test_entry_point_plugin():
no_plugins_found = entry_point_plugins("errbot.no_plugins")
assert [] == no_plugins_found