forked from equinor/komodo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cli.py
More file actions
236 lines (200 loc) · 7.26 KB
/
Copy pathtest_cli.py
File metadata and controls
236 lines (200 loc) · 7.26 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import os
import shutil
import sys
from pathlib import Path
import pytest
from komodo.cli import cli_main
from tests import _get_test_root
@pytest.mark.parametrize(
"args",
[
(
"--download",
"--build",
"--install",
"--prefix",
"prefix",
"--cache",
"cache",
"--tmp",
"tmp",
"--release",
"nominal_release",
"--pip",
"/usr/bin/true",
os.path.join(_get_test_root(), "data/cli/nominal_release.yml"),
os.path.join(_get_test_root(), "data/cli/nominal_repository.yml"),
"--extra-data-dirs",
os.path.join(_get_test_root(), "data/cli"),
os.path.join(_get_test_root(), "data/cli/hackres"),
os.path.join(_get_test_root(), "data/cli/hackgit"),
),
],
)
def test_main(args, tmpdir):
tmpdir = str(tmpdir)
shutil.copytree(
os.path.join(_get_test_root(), "data/cli/hackres"),
os.path.join(tmpdir, "hackres"),
)
shutil.copytree(
os.path.join(_get_test_root(), "data/cli/hackgit"),
os.path.join(tmpdir, "hackgit"),
)
sys.argv = [
"kmd",
"--workspace",
tmpdir,
]
sys.argv.extend(list(args))
cli_main()
release_name = args[10]
release_path = os.path.join(tmpdir, "prefix", release_name)
assert os.path.exists(os.path.join(release_path, "root/lib/hackres.so"))
assert os.path.exists(os.path.join(release_path, "root/lib/python4.2.so"))
assert os.path.exists(os.path.join(release_path, "root/bin/python4.2"))
assert os.path.exists(os.path.join(release_path, "enable"))
assert os.path.exists(os.path.join(release_path, "enable.csh"))
fname = "root/bin/some-github-binary-artifact"
downloaded_file = os.path.join(release_path, fname)
assert os.path.exists(downloaded_file)
assert os.access(downloaded_file, os.X_OK)
with open(os.path.join(release_path, release_name), encoding="utf-8") as releasedoc:
releasedoc_content = releasedoc.read()
# ensure the alias is used when resolving the version
assert "version: null" not in releasedoc_content
# Ensure that the commit hash is reported as version and not the
# branch "test-hack" specified in nominal_repository.yml
assert "test-hash" not in releasedoc_content
assert "version: 7f4405928bd16de496522d9301c377c7bcca5ef0" in releasedoc_content
@pytest.mark.parametrize(
"args",
[
(
os.path.join(_get_test_root(), "data/cli/minimal_release.yml"),
os.path.join(_get_test_root(), "data/cli/minimal_repository.yml"),
"--prefix",
"prefix",
"--release",
"minimal_release",
"--extra-data-dirs", # Required to find test_python_builtin.sh.
os.path.join(_get_test_root(), "data/cli"),
),
],
)
def test_minimal_main(args, tmpdir):
"""Check that a minimal example, more like that from the README, also works.
Without --locations-config, this should not produce the scripts local & local.csh.
"""
tmpdir = str(tmpdir)
sys.argv = [
"kmd",
"--workspace",
tmpdir,
]
sys.argv.extend(list(args))
cli_main()
release_name = args[5]
release_path = os.path.join(tmpdir, "prefix", release_name)
assert os.path.exists(os.path.join(release_path, "enable"))
assert os.path.exists(os.path.join(release_path, "enable.csh"))
assert not os.path.exists(os.path.join(release_path, "local"))
assert not os.path.exists(os.path.join(release_path, "local.csh"))
def test_no_overwrite_by_default(tmpdir):
sys.argv = [
"kmd",
"--workspace",
str(tmpdir),
os.path.join(_get_test_root(), "data/cli/minimal_release.yml"),
os.path.join(_get_test_root(), "data/cli/minimal_repository.yml"),
"--prefix",
"prefix",
"--release",
"existing_release",
"--extra-data-dirs", # Required to find test_python_builtin.sh.
os.path.join(_get_test_root(), "data/cli"),
]
cli_main()
with pytest.raises(
RuntimeError, match="Downloading to non-empty directory downloads"
):
cli_main()
# Try another rerun after we have removed the downloads and remainder from
# failed build above:
shutil.rmtree(tmpdir / "downloads")
shutil.rmtree(tmpdir / ".existing_release")
with pytest.raises(RuntimeError, match="Only bleeding builds can be overwritten"):
cli_main()
def test_bleeding_overwrite_by_default(tmpdir):
sys.argv = [
"kmd",
"--workspace",
str(tmpdir),
os.path.join(_get_test_root(), "data/cli/minimal_release.yml"),
os.path.join(_get_test_root(), "data/cli/minimal_repository.yml"),
"--prefix",
"prefix",
"--release",
"some_bleeding_release",
"--extra-data-dirs", # Required to find test_python_builtin.sh.
os.path.join(_get_test_root(), "data/cli"),
]
cli_main()
# Remove non-interesting leftovers from first build:
shutil.rmtree(tmpdir / "downloads")
shutil.rmtree(tmpdir / ".some_bleeding_release")
# Assert that we can overwrite the build inside "some_bleeding_release"
cli_main()
def test_overwrite_if_option_is_set(tmpdir):
sys.argv = [
"kmd",
"--workspace",
str(tmpdir),
"--overwrite",
os.path.join(_get_test_root(), "data/cli/minimal_release.yml"),
os.path.join(_get_test_root(), "data/cli/minimal_repository.yml"),
"--prefix",
"prefix",
"--release",
"some_release",
"--extra-data-dirs", # Required to find test_python_builtin.sh.
os.path.join(_get_test_root(), "data/cli"),
]
cli_main()
# Remove non-interesting leftovers from first build:
shutil.rmtree(tmpdir / "downloads")
shutil.rmtree(tmpdir / ".some_release")
# Assert that we can overwrite the build inside "some_release"
cli_main()
def test_bleeding_builds_marked_for_deletion_are_removed(tmpdir):
prefix_path = Path(tmpdir).absolute()
prefix_path_str = str(prefix_path)
sys.argv = [
"kmd",
"--workspace",
str(tmpdir),
os.path.join(_get_test_root(), "data/cli/minimal_release.yml"),
os.path.join(_get_test_root(), "data/cli/minimal_repository.yml"),
"--prefix",
prefix_path_str,
"--release",
"some_bleeding_release",
"--extra-data-dirs", # Required to find test_python_builtin.sh.
os.path.join(_get_test_root(), "data/cli"),
]
test_dirs = [
prefix_path_str + "/some_bleeding_release.delete-7632",
prefix_path_str + "/some_bleeding_release.delete-4342",
prefix_path_str + "/some_bleeding_release.delete-1234",
]
def count_release_folders_to_be_deleted() -> int:
release_dir_glob = [
str(p.absolute())
for p in list(Path(prefix_path).glob("some_bleeding_release.delete-*"))
]
return len(release_dir_glob) if release_dir_glob else 0
for test_dir in test_dirs:
os.makedirs(test_dir)
assert count_release_folders_to_be_deleted() == len(test_dirs)
cli_main()
assert count_release_folders_to_be_deleted() == 0