-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
pyenv.bats
320 lines (246 loc) · 7.21 KB
/
pyenv.bats
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#!/usr/bin/env bats
load test_helper
export PYENV_ROOT="${TMP}/pyenv"
setup() {
stub pyenv-hooks 'install : true'
stub pyenv-rehash true
}
stub_python_build_lib() {
stub python-build "--lib : $BATS_TEST_DIRNAME/../bin/python-build --lib" "$@"
}
stub_python_build_no_latest() {
stub python-build "${@:-echo python-build \"\$@\"}"
}
stub_python_build() {
stub_python_build_no_latest "$@"
stub pyenv-latest false
}
@test "install a single version" {
stub_python_build_lib
stub_python_build
run pyenv-install 3.4.2
assert_success "python-build 3.4.2 ${PYENV_ROOT}/versions/3.4.2"
unstub python-build
}
@test "install multiple versions" {
stub_python_build_lib
stub_python_build
stub_python_build
run pyenv-install 3.4.1 3.4.2
assert_success
assert_output <<OUT
python-build 3.4.1 ${TMP}/pyenv/versions/3.4.1
python-build 3.4.2 ${TMP}/pyenv/versions/3.4.2
OUT
unstub python-build
unstub pyenv-latest
}
@test "install multiple versions, some fail" {
stub_python_build_lib
stub_python_build 'echo "fail: python-build" "$@"; false'
run pyenv-install 3.4.1 3.4.2
assert_failure
assert_output <<OUT
fail: python-build 3.4.1 ${TMP}/pyenv/versions/3.4.1
OUT
unstub python-build
}
@test "install resolves a prefix" {
stub_python_build_lib
for i in {1..3}; do stub_python_build_no_latest; done
stub pyenv-latest \
'-q -k 3.4 : echo 3.4.2' \
'-q -k 3.5.1 : false' \
'-q -k 3.5 : echo 3.5.2'
run pyenv-install 3.4 3.5.1 3.5
assert_success <<OUT
python-build 3.4.2 ${PYENV_ROOT}/versions/3.4.2
python-build 3.5.1 ${PYENV_ROOT}/versions/3.5.1
python-build 3.5.2 ${PYENV_ROOT}/versions/3.5.2
OUT
unstub python-build
}
@test "install resolves :latest" {
stub_python_build_lib
for i in {1..2}; do stub_python_build '--definitions : echo -e 3.4.2\\n3.5.1\\n3.5.2'; done
for i in {1..2}; do stub_python_build; done
pyenv-hooks install; unstub pyenv-hooks
PYENV_INSTALL_ROOT="$BATS_TEST_DIRNAME/../../.."
export PYENV_HOOK_PATH="$PYENV_INSTALL_ROOT/pyenv.d"
[[ -d "$PYENV_INSTALL_ROOT/libexec" ]] || skip "python-build is installed separately from pyenv"
export PATH="$PATH:$PYENV_INSTALL_ROOT/libexec"
run pyenv-install 3.4:latest 3:latest
assert_success <<!
python-build 3.4.2 ${PYENV_ROOT}/versions/3.4.2
python-build 3.5.2 ${PYENV_ROOT}/versions/3.5.2
!
unstub python-build
}
@test "install installs local versions by default" {
stub_python_build_lib
stub_python_build
stub_python_build
stub pyenv-local 'echo 3.4.2; echo 3.4.1'
run pyenv-install
assert_success <<OUT
python-build 3.4.2
python-build 3.4.1
OUT
unstub python-build
unstub pyenv-local
}
@test "list available versions" {
stub_python_build_lib
stub_python_build "--definitions : echo 2.6.9 2.7.9-rc1 2.7.9-rc2 3.4.2 | tr ' ' $'\\n'"
run pyenv-install --list
assert_success
assert_output <<OUT
Available versions:
2.6.9
2.7.9-rc1
2.7.9-rc2
3.4.2
OUT
unstub python-build
}
@test "upgrade instructions given for a nonexistent version" {
stub brew false
stub_python_build_lib
stub_python_build 'echo ERROR >&2 && exit 2'
stub_python_build "--definitions : echo 2.6.9 2.7.9-rc1 2.7.9-rc2 3.4.2 | tr ' ' $'\\n'"
run pyenv-install 2.7.9
assert_failure
assert_output <<OUT
ERROR
The following versions contain \`2.7.9' in the name:
2.7.9-rc1
2.7.9-rc2
See all available versions with \`pyenv install --list'.
If the version you need is missing, try upgrading pyenv:
cd ${BATS_TEST_DIRNAME}/../../.. && git pull && cd -
OUT
unstub python-build
}
@test "homebrew upgrade instructions given when pyenv is homebrew-installed" {
stub brew "--prefix : echo '${BATS_TEST_DIRNAME%/*}'"
stub_python_build_lib
stub_python_build 'echo ERROR >&2 && exit 2' \
"--definitions : true"
run pyenv-install 1.9.3
assert_failure
assert_output <<OUT
ERROR
See all available versions with \`pyenv install --list'.
If the version you need is missing, try upgrading pyenv:
brew update && brew upgrade pyenv
OUT
unstub brew
unstub python-build
}
@test "no build definitions from plugins" {
assert [ ! -e "${PYENV_ROOT}/plugins" ]
stub_python_build_lib
stub_python_build 'echo $PYTHON_BUILD_DEFINITIONS'
run pyenv-install 3.4.2
assert_success ""
unstub python-build
}
@test "some build definitions from plugins" {
mkdir -p "${PYENV_ROOT}/plugins/foo/share/python-build"
mkdir -p "${PYENV_ROOT}/plugins/bar/share/python-build"
stub_python_build_lib
stub_python_build "echo \$PYTHON_BUILD_DEFINITIONS | tr ':' $'\\n'"
run pyenv-install 3.4.2
assert_success
assert_output <<OUT
${PYENV_ROOT}/plugins/bar/share/python-build
${PYENV_ROOT}/plugins/foo/share/python-build
OUT
unstub python-build
}
@test "list build definitions from plugins" {
mkdir -p "${PYENV_ROOT}/plugins/foo/share/python-build"
mkdir -p "${PYENV_ROOT}/plugins/bar/share/python-build"
stub_python_build_lib
stub_python_build "--definitions : echo \$PYTHON_BUILD_DEFINITIONS | tr ':' $'\\n'"
run pyenv-install --list
assert_success
assert_output <<OUT
Available versions:
${PYENV_ROOT}/plugins/bar/share/python-build
${PYENV_ROOT}/plugins/foo/share/python-build
OUT
unstub python-build
}
@test "completion results include build definitions from plugins" {
mkdir -p "${PYENV_ROOT}/plugins/foo/share/python-build"
mkdir -p "${PYENV_ROOT}/plugins/bar/share/python-build"
stub_python_build "--definitions : echo \$PYTHON_BUILD_DEFINITIONS | tr ':' $'\\n'"
run pyenv-install --complete
assert_success
assert_output <<OUT
--list
--force
--skip-existing
--keep
--patch
--verbose
--version
--debug
${PYENV_ROOT}/plugins/bar/share/python-build
${PYENV_ROOT}/plugins/foo/share/python-build
OUT
unstub python-build
}
@test "not enough arguments for pyenv-install if no local version" {
stub_python_build_lib
stub pyenv-help 'install : true'
run pyenv-install
assert_failure
unstub pyenv-help
assert_output ""
}
@test "show help for pyenv-install" {
stub pyenv-help 'install : true'
run pyenv-install -h
assert_success
unstub pyenv-help
}
@test "pyenv-install has usage help preface" {
run head "$(command -v pyenv-install)"
assert_output_contains 'Usage: pyenv install'
}
@test "not enough arguments pyenv-uninstall" {
stub pyenv-help 'uninstall : true'
run pyenv-uninstall
assert_failure
unstub pyenv-help
}
@test "multiple arguments for pyenv-uninstall" {
mkdir -p "${PYENV_ROOT}/versions/3.4.1"
mkdir -p "${PYENV_ROOT}/versions/3.4.2"
run pyenv-uninstall -f 3.4.1 3.4.2
assert_success
refute [ -d "${PYENV_ROOT}/versions/3.4.1" ]
refute [ -d "${PYENV_ROOT}/versions/3.4.2" ]
}
@test "invalid arguments for pyenv-uninstall" {
mkdir -p "${PYENV_ROOT}/versions/3.10.3"
mkdir -p "${PYENV_ROOT}/versions/3.10.4"
run pyenv-uninstall -f 3.10.3 --invalid-option 3.10.4
assert_failure
assert [ -d "${PYENV_ROOT}/versions/3.10.3" ]
assert [ -d "${PYENV_ROOT}/versions/3.10.4" ]
rmdir "${PYENV_ROOT}/versions/3.10.3"
rmdir "${PYENV_ROOT}/versions/3.10.4"
}
@test "show help for pyenv-uninstall" {
stub pyenv-help 'uninstall : true'
run pyenv-uninstall -h
assert_success
unstub pyenv-help
}
@test "pyenv-uninstall has usage help preface" {
run head "$(command -v pyenv-uninstall)"
assert_output_contains 'Usage: pyenv uninstall'
}