Skip to content

Commit bdcfb08

Browse files
committed
Update tests and add more test cases
Update the existing tests based on new behavior/output format. Add additional tests to cover scenarios that were not previously tested.
1 parent 823cd5f commit bdcfb08

1 file changed

Lines changed: 92 additions & 18 deletions

File tree

test/virtualenvs.bats

Lines changed: 92 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,131 @@ setup() {
1010
ln -s "${PYENV_ROOT}/versions/3.3.3/envs/venv33" "${PYENV_ROOT}/versions/venv33"
1111
}
1212

13-
@test "list virtual environments only" {
13+
@test "list virtual environments" {
1414
stub pyenv-version-name ": echo system"
15-
stub pyenv-virtualenv-prefix "2.7.6 : false"
16-
stub pyenv-virtualenv-prefix "3.3.3 : false"
17-
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/2.7.6\""
18-
stub pyenv-virtualenv-prefix "venv33 : echo \"${PYENV_ROOT}/versions/3.3.3\""
15+
stub pyenv-version-origin ""
1916

2017
run pyenv-virtualenvs
2118

2219
assert_success
2320
assert_output <<OUT
2421
2.7.6/envs/venv27
2522
3.3.3/envs/venv33
23+
venv27 --> ${PYENV_ROOT}/versions/2.7.6/envs/venv27
24+
venv33 --> ${PYENV_ROOT}/versions/3.3.3/envs/venv33
2625
OUT
2726

28-
# unstub pyenv-version-name
29-
# unstub pyenv-virtualenv-prefix
27+
unstub pyenv-version-name
3028
}
3129

3230
@test "list virtual environments with hit prefix" {
33-
stub pyenv-version-name ": echo venv33"
34-
stub pyenv-virtualenv-prefix "2.7.6 : false"
35-
stub pyenv-virtualenv-prefix "3.3.3 : false"
36-
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/2.7.6\""
37-
stub pyenv-virtualenv-prefix "venv33 : echo \"${PYENV_ROOT}/versions/3.3.3\""
31+
stub pyenv-version-name ": echo 3.3.3/envs/venv33"
32+
stub pyenv-version-origin ": echo PYENV_VERSION"
3833

3934
run pyenv-virtualenvs
4035

4136
assert_success
4237
assert_output <<OUT
4338
2.7.6/envs/venv27
44-
* 3.3.3/envs/venv33
39+
* 3.3.3/envs/venv33 (set by PYENV_VERSION)
40+
venv27 --> ${PYENV_ROOT}/versions/2.7.6/envs/venv27
41+
venv33 --> ${PYENV_ROOT}/versions/3.3.3/envs/venv33
4542
OUT
4643

47-
# unstub pyenv-version-name
48-
# unstub pyenv-virtualenv-prefix
44+
unstub pyenv-version-name
45+
unstub pyenv-version-origin
4946
}
5047

51-
@test "list virtual environments with --bare" {
48+
@test "list bare virtual environments" {
5249
stub pyenv-virtualenv-prefix "2.7.6 : false"
5350
stub pyenv-virtualenv-prefix "3.3.3 : false"
5451
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/2.7.6\""
5552
stub pyenv-virtualenv-prefix "venv33 : echo \"${PYENV_ROOT}/versions/3.3.3\""
5653

57-
run pyenv-virtualenvs --bare --only-aliases
54+
run pyenv-virtualenvs --bare
5855

5956
assert_success
6057
assert_output <<OUT
58+
2.7.6/envs/venv27
59+
3.3.3/envs/venv33
6160
venv27
6261
venv33
6362
OUT
63+
}
64+
65+
@test "list bare virtual environments without aliases" {
66+
run pyenv-virtualenvs --bare --skip-aliases
67+
68+
assert_success
69+
assert_output <<OUT
70+
2.7.6/envs/venv27
71+
3.3.3/envs/venv33
72+
OUT
73+
}
74+
75+
@test "list virtual environments without aliases" {
76+
stub pyenv-version-name ": echo system"
77+
stub pyenv-version-origin ""
78+
79+
run pyenv-virtualenvs --skip-aliases
80+
81+
assert_success
82+
assert_output <<OUT
83+
2.7.6/envs/venv27
84+
3.3.3/envs/venv33
85+
OUT
86+
87+
unstub pyenv-version-name
88+
}
89+
90+
@test "hit prefix matches alias version name" {
91+
stub pyenv-version-name ": echo venv27"
92+
stub pyenv-version-origin ": echo PYENV_VERSION"
6493

65-
unstub pyenv-virtualenv-prefix
94+
run pyenv-virtualenvs
95+
96+
assert_success
97+
assert_output <<OUT
98+
2.7.6/envs/venv27
99+
3.3.3/envs/venv33
100+
* venv27 --> ${PYENV_ROOT}/versions/2.7.6/envs/venv27 (set by PYENV_VERSION)
101+
venv33 --> ${PYENV_ROOT}/versions/3.3.3/envs/venv33
102+
OUT
103+
104+
unstub pyenv-version-name
105+
unstub pyenv-version-origin
106+
}
107+
108+
@test "no virtualenvs warning" {
109+
rm -rf "${PYENV_ROOT}/versions"
110+
mkdir -p "${PYENV_ROOT}/versions"
111+
stub pyenv-version-name ": echo system"
112+
stub pyenv-version-origin ""
113+
114+
run pyenv-virtualenvs
115+
116+
assert_failure
117+
assert_output "Warning: no Python virtualenv detected on the system"
118+
119+
unstub pyenv-version-name
120+
}
121+
122+
@test "no warning with --bare and no virtualenvs" {
123+
rm -rf "${PYENV_ROOT}/versions"
124+
mkdir -p "${PYENV_ROOT}/versions"
125+
126+
run pyenv-virtualenvs --bare
127+
128+
assert_success
129+
assert_output ""
130+
}
131+
132+
@test "completions output" {
133+
run pyenv-virtualenvs --complete
134+
135+
assert_success
136+
assert_output <<OUT
137+
--bare
138+
--skip-aliases
139+
OUT
66140
}

0 commit comments

Comments
 (0)