Skip to content

Commit cbaa29a

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 b93aa47 commit cbaa29a

1 file changed

Lines changed: 89 additions & 23 deletions

File tree

test/virtualenvs.bats

Lines changed: 89 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,123 @@ 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\""
1915

2016
run pyenv-virtualenvs
2117

2218
assert_success
2319
assert_output <<OUT
2420
2.7.6/envs/venv27
2521
3.3.3/envs/venv33
22+
venv27 --> ${PYENV_ROOT}/versions/2.7.6/envs/venv27
23+
venv33 --> ${PYENV_ROOT}/versions/3.3.3/envs/venv33
2624
OUT
2725

28-
# unstub pyenv-version-name
29-
# unstub pyenv-virtualenv-prefix
26+
unstub pyenv-version-name
3027
}
3128

3229
@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\""
30+
stub pyenv-version-name ": echo 3.3.3/envs/venv33"
31+
stub pyenv-version-origin ": echo PYENV_VERSION"
3832

3933
run pyenv-virtualenvs
4034

4135
assert_success
4236
assert_output <<OUT
4337
2.7.6/envs/venv27
44-
* 3.3.3/envs/venv33
38+
* 3.3.3/envs/venv33 (set by PYENV_VERSION)
39+
venv27 --> ${PYENV_ROOT}/versions/2.7.6/envs/venv27
40+
venv33 --> ${PYENV_ROOT}/versions/3.3.3/envs/venv33
4541
OUT
4642

47-
# unstub pyenv-version-name
48-
# unstub pyenv-virtualenv-prefix
43+
unstub pyenv-version-name
44+
unstub pyenv-version-origin
4945
}
5046

51-
@test "list virtual environments with --bare" {
52-
stub pyenv-virtualenv-prefix "2.7.6 : false"
53-
stub pyenv-virtualenv-prefix "3.3.3 : false"
54-
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/2.7.6\""
55-
stub pyenv-virtualenv-prefix "venv33 : echo \"${PYENV_ROOT}/versions/3.3.3\""
56-
57-
run pyenv-virtualenvs --bare --only-aliases
47+
@test "list bare virtual environments" {
48+
run pyenv-virtualenvs --bare
5849

5950
assert_success
6051
assert_output <<OUT
52+
2.7.6/envs/venv27
53+
3.3.3/envs/venv33
6154
venv27
6255
venv33
6356
OUT
57+
}
58+
59+
@test "list bare virtual environments without aliases" {
60+
run pyenv-virtualenvs --bare --skip-aliases
61+
62+
assert_success
63+
assert_output <<OUT
64+
2.7.6/envs/venv27
65+
3.3.3/envs/venv33
66+
OUT
67+
}
68+
69+
@test "list virtual environments without aliases" {
70+
stub pyenv-version-name ": echo system"
71+
72+
run pyenv-virtualenvs --skip-aliases
73+
74+
assert_success
75+
assert_output <<OUT
76+
2.7.6/envs/venv27
77+
3.3.3/envs/venv33
78+
OUT
79+
80+
unstub pyenv-version-name
81+
}
82+
83+
@test "hit prefix matches alias version name" {
84+
stub pyenv-version-name ": echo venv27"
85+
stub pyenv-version-origin ": echo PYENV_VERSION"
86+
87+
run pyenv-virtualenvs
88+
89+
assert_success
90+
assert_output <<OUT
91+
2.7.6/envs/venv27
92+
3.3.3/envs/venv33
93+
* venv27 --> ${PYENV_ROOT}/versions/2.7.6/envs/venv27 (set by PYENV_VERSION)
94+
venv33 --> ${PYENV_ROOT}/versions/3.3.3/envs/venv33
95+
OUT
96+
97+
unstub pyenv-version-name
98+
unstub pyenv-version-origin
99+
}
100+
101+
@test "no virtualenvs warning" {
102+
rm -rf "${PYENV_ROOT}/versions"
103+
mkdir -p "${PYENV_ROOT}/versions"
104+
stub pyenv-version-name ": echo system"
105+
106+
run pyenv-virtualenvs
107+
108+
assert_failure
109+
assert_output "Warning: no Python virtualenv detected on the system"
64110

65-
unstub pyenv-virtualenv-prefix
111+
unstub pyenv-version-name
112+
}
113+
114+
@test "no warning with --bare and no virtualenvs" {
115+
rm -rf "${PYENV_ROOT}/versions"
116+
mkdir -p "${PYENV_ROOT}/versions"
117+
118+
run pyenv-virtualenvs --bare
119+
120+
assert_success
121+
assert_output ""
122+
}
123+
124+
@test "completions output" {
125+
run pyenv-virtualenvs --complete
126+
127+
assert_success
128+
assert_output <<OUT
129+
--bare
130+
--skip-aliases
131+
OUT
66132
}

0 commit comments

Comments
 (0)