-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathtest_pip_autoremove.py
54 lines (40 loc) · 1.3 KB
/
test_pip_autoremove.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
import subprocess
import pkg_resources
import pip_autoremove
def test_find_all_dead():
graph = {
"Flask": set(),
"Jinja2": {"Flask", "Sphinx"},
"MarkupSafe": {"Jinja2"},
"Werkzeug": {"Flask"},
"itsdangerous": {"Flask"},
"Sphinx": set(),
"pip": set(),
"setuptools": set(),
}
start = {"Flask"}
expected = {"Flask", "Werkzeug", "itsdangerous"}
dead = pip_autoremove.find_all_dead(graph, start)
assert dead == expected
start = {"Sphinx"}
dead = pip_autoremove.find_all_dead(graph, start)
assert dead == start
start = {"Sphinx", "Flask"}
expected = {"Flask", "Werkzeug", "itsdangerous", "Sphinx", "Jinja2", "MarkupSafe"}
dead = pip_autoremove.find_all_dead(graph, start)
print(dead)
assert dead == expected
def install_dist(req):
subprocess.check_call(["pip", "install", req])
def has_dist(req):
req = pkg_resources.Requirement.parse(req)
working_set = pkg_resources.WorkingSet()
return working_set.find(req)
def test_main():
expected = ["Flask", "Jinja2", "MarkupSafe", "Werkzeug", "itsdangerous"]
install_dist("Flask")
for name in expected:
assert has_dist(name)
pip_autoremove.main(["-y", "Flask"])
for name in expected:
assert not has_dist(name)