-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_packages_full.py
154 lines (122 loc) · 4.14 KB
/
test_packages_full.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
151
152
153
154
URANIUM_PY = """
def main(build):
build.packages.install("nose")
import nose
assert nose is not None
""".strip()
URANIUM_PY_UPDATE = """
def main(build):
build.packages.install("nose" {0})
import nose
print(nose.__version__)
print("test")
""".strip()
URANIUM_PY_UNINSTALL = """
def main(build):
build.packages.install("pyyaml")
import yaml
assert yaml is not None
build.packages.uninstall("pyyaml")
import importlib
try:
importlib.reload(yaml)
exist = True
except Exception:
exist = False
assert exist == False
""".strip()
from uranium.scripts import execute_script
from .conftest import URANIUM_SOURCE_ROOT
def test_install(tmpdir):
# we need to create a virtualenv
tmpdir.join("ubuild.py").write(URANIUM_PY)
code, out, err = execute_script(
"uranium_standalone", "--uranium-dir", URANIUM_SOURCE_ROOT,
cwd=tmpdir.strpath
)
print("stdout:\n" + str(out))
print("stderr:\n" + str(err))
assert code == 0
def test_uninstall(tmpdir):
# we need to create a virtualenv
tmpdir.join("ubuild.py").write(URANIUM_PY_UNINSTALL)
code, out, err = execute_script(
"uranium_standalone", "--uranium-dir", URANIUM_SOURCE_ROOT,
cwd=tmpdir.strpath
)
print("stdout:\n" + str(out))
print("stderr:\n" + str(err))
assert code == 0
def test_package_cache(tmpdir):
""" don't event attempt to call pip, if a package already exists. """
tmpdir.join("ubuild.py").write(URANIUM_PY)
execute_script(
"uranium_standalone", "--uranium-dir", URANIUM_SOURCE_ROOT,
cwd=tmpdir.strpath
)
code, out, err = execute_script(
"uranium_standalone", "--uranium-dir", URANIUM_SOURCE_ROOT,
cwd=tmpdir.strpath
)
print(out)
print(err)
assert "Requirement already satisified" not in str(out)
assert code == 0
def test_update(tmpdir):
""" update should update versions to the latest. """
hard_version = URANIUM_PY_UPDATE.format(',version="==1.3.1"')
tmpdir.join("ubuild.py").write(hard_version)
status, out, err = execute_script("uranium_standalone", "--uranium-dir", URANIUM_SOURCE_ROOT,
cwd=tmpdir.strpath)
assert "1.3.1" in out.decode("utf-8")
no_version = URANIUM_PY_UPDATE.format('')
tmpdir.join("ubuild.py").write(no_version)
status, out, err = execute_script("uranium_standalone", "--uranium-dir", URANIUM_SOURCE_ROOT,
cwd=tmpdir.strpath)
assert "1.3.1" in out.decode("utf-8")
update_version = URANIUM_PY_UPDATE.format(',upgrade=True')
tmpdir.join("ubuild.py").write(update_version)
status, out, err = execute_script("uranium_standalone", "--uranium-dir", URANIUM_SOURCE_ROOT,
cwd=tmpdir.strpath)
assert "1.3.1" in out.decode("utf-8")
def test_versions_dict_updated(tmpdir):
""" the versions dict should be updated once a version is installed. """
UBUILD = """
def main(build):
build.packages.install("nose")
print(build.packages.versions["nose"])
print("fooo")
""".strip()
# we need to create a virtualenv
tmpdir.join("ubuild.py").write(UBUILD)
code, out, err = execute_script(
"uranium_standalone", "--uranium-dir", URANIUM_SOURCE_ROOT,
cwd=tmpdir.strpath
)
print("stdout:\n" + str(out))
print("stderr:\n" + str(err))
assert code == 0
def test_executable_relocatable_after_install(tmpdir):
"""
an executable installed from a package should be
using the virtualenv relocatable version.
"""
UBUILD = """
import os
def main(build):
build.packages.install("tox")
nose_path = os.path.join(build.root, "bin", "tox")
with open(nose_path) as fh:
contents = fh.read()
print(contents)
assert build.root not in contents
""".strip()
# we need to create a virtualenv
tmpdir.join("ubuild.py").write(UBUILD)
code, out, err = execute_script(
"uranium_standalone", "--uranium-dir", URANIUM_SOURCE_ROOT,
cwd=tmpdir.strpath
)
print("stdout:\n" + str(out))
print("stderr:\n" + str(err))
assert code == 0