@@ -21,16 +21,6 @@ setUp () {
21
21
rm -f " $test_dir /catch_output"
22
22
}
23
23
24
- test_mkvirtualenv () {
25
- mkvirtualenv " env1"
26
- assertTrue " Environment directory was not created" " [ -d $WORKON_HOME /env1 ]"
27
- for hook in postactivate predeactivate postdeactivate
28
- do
29
- assertTrue " env1 $hook was not created" " [ -f $WORKON_HOME /env1/bin/$hook ]"
30
- assertTrue " env1 $hook is not executable" " [ -x $WORKON_HOME /env1/bin/$hook ]"
31
- done
32
- }
33
-
34
24
test_virtualenvwrapper_initialize () {
35
25
virtualenvwrapper_initialize
36
26
for hook in premkvirtualenv postmkvirtualenv prermvirtualenv postrmvirtualenv preactivate postactivate predeactivate postdeactivate
@@ -40,254 +30,11 @@ test_virtualenvwrapper_initialize() {
40
30
done
41
31
}
42
32
43
- test_virtualenvwrapper_run_hook () {
44
- echo " echo run >> \" $test_dir /catch_output\" " >> " $WORKON_HOME /test_hook"
45
- chmod +x " $WORKON_HOME /test_hook"
46
- virtualenvwrapper_run_hook " $WORKON_HOME /test_hook"
47
- output=$( cat " $test_dir /catch_output" )
48
- expected=" run"
49
- assertSame " $expected " " $output "
50
- }
51
-
52
- test_virtualenvwrapper_run_hook_permissions () {
53
- echo " echo run >> \" $test_dir /catch_output\" " >> " $WORKON_HOME /test_hook"
54
- chmod -x " $WORKON_HOME /test_hook"
55
- virtualenvwrapper_run_hook " $WORKON_HOME /test_hook"
56
- output=$( cat " $test_dir /catch_output" )
57
- expected=" "
58
- assertSame " $expected " " $output "
59
- }
60
-
61
33
test_get_python_version () {
62
34
expected=$( python -V 2>&1 | cut -f2 -d' ' | cut -f-2 -d.)
63
35
actual=$( virtualenvwrapper_get_python_version)
64
36
assertSame " $expected " " $actual "
65
37
}
66
38
67
- test_cdvirtual () {
68
- pushd " $( pwd) " > /dev/null
69
- cdvirtualenv
70
- assertSame " $VIRTUAL_ENV " " $( pwd) "
71
- cdvirtualenv bin
72
- assertSame " $VIRTUAL_ENV /bin" " $( pwd) "
73
- popd > /dev/null
74
- }
75
-
76
- test_cdsitepackages () {
77
- pushd " $( pwd) " > /dev/null
78
- cdsitepackages
79
- pyvers=$( python -V 2>&1 | cut -f2 -d' ' | cut -f1-2 -d.)
80
- sitepackages=" $VIRTUAL_ENV /lib/python${pyvers} /site-packages"
81
- assertSame " $sitepackages " " $( pwd) "
82
- popd > /dev/null
83
- }
84
-
85
- test_cdsitepackages_with_arg () {
86
- pushd " $( pwd) " > /dev/null
87
- pyvers=$( python -V 2>&1 | cut -f2 -d' ' | cut -f1-2 -d.)
88
- sitepackage_subdir=" $VIRTUAL_ENV /lib/python${pyvers} /site-packages/subdir"
89
- mkdir -p " ${sitepackage_subdir} "
90
- cdsitepackages subdir
91
- assertSame " $sitepackage_subdir " " $( pwd) "
92
- popd > /dev/null
93
- }
94
-
95
- test_mkvirtualenv_activates () {
96
- mkvirtualenv " env2"
97
- assertTrue virtualenvwrapper_verify_active_environment
98
- assertSame " env2" $( basename " $VIRTUAL_ENV " )
99
- }
100
-
101
- test_mkvirtualenv_hooks () {
102
- export pre_test_dir=$( cd " $test_dir " ; pwd)
103
- echo " echo GLOBAL premkvirtualenv >> \" $pre_test_dir /catch_output\" " >> " $WORKON_HOME /premkvirtualenv"
104
- chmod +x " $WORKON_HOME /premkvirtualenv"
105
- echo " echo GLOBAL postmkvirtualenv >> $test_dir /catch_output" > " $WORKON_HOME /postmkvirtualenv"
106
- mkvirtualenv " env3"
107
- output=$( cat " $test_dir /catch_output" )
108
- expected=" GLOBAL premkvirtualenv
109
- GLOBAL postmkvirtualenv"
110
- assertSame " $expected " " $output "
111
- rm -f " $WORKON_HOME /premkvirtualenv"
112
- rm -f " $WORKON_HOME /postmkvirtualenv"
113
- deactivate
114
- rmvirtualenv " env3"
115
- }
116
-
117
- test_no_virtualenv () {
118
- old_path=" $PATH "
119
- PATH=" /usr/bin:/usr/local/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$HOME /bin"
120
- mkvirtualenv should_not_be_created # 2>/dev/null
121
- RC=$?
122
- # Restore the path before testing because
123
- # the test script depends on commands in the
124
- # path.
125
- export PATH=" $old_path "
126
- assertSame " $RC " " 1"
127
- }
128
-
129
- # test_mkvirtualenv_sitepackages () {
130
- # # Without the option verify that site-packages are copied.
131
- # mkvirtualenv "env3"
132
- # assertSame "env3" "$(basename $VIRTUAL_ENV)"
133
- # pyvers=$(python -V 2>&1 | cut -f2 -d' ' | cut -f1-2 -d.)
134
- # sitepackages="$VIRTUAL_ENV/lib/python${pyvers}/site-packages"
135
- # #cat "$sitepackages/easy-install.pth"
136
- # assertTrue "Do not have expected virtualenv.py" "[ -f $sitepackages/virtualenv.py ]"
137
- # rmvirtualenv "env3"
138
- #
139
- # # With the argument, verify that they are not copied.
140
- # mkvirtualenv --no-site-packages "env4"
141
- # assertSame "env4" $(basename "$VIRTUAL_ENV")
142
- # pyvers=$(python -V 2>&1 | cut -f2 -d' ' | cut -f1-2 -d.)
143
- # sitepackages="$VIRTUAL_ENV/lib/python${pyvers}/site-packages"
144
- # assertTrue "[ -f $sitepackages/setuptools.pth ]"
145
- # assertTrue "[ -f $sitepackages/easy-install.pth ]"
146
- # assertFalse "Have virtualenv.py but should not" "[ -f $sitepackages/virtualenv.py ]"
147
- # rmvirtualenv "env4"
148
- # }
149
-
150
- test_workon () {
151
- workon env1
152
- assertTrue virtualenvwrapper_verify_active_environment
153
- assertSame " env1" $( basename " $VIRTUAL_ENV " )
154
- }
155
-
156
- test_workon_activate_hooks () {
157
- for t in pre post
158
- do
159
- echo " echo GLOBAL ${t} activate >> \" $test_dir /catch_output\" " >> " $WORKON_HOME /${t} activate"
160
- chmod +x " $WORKON_HOME /${t} activate"
161
- echo " echo ENV ${t} activate >> \" $test_dir /catch_output\" " >> " $WORKON_HOME /env1/bin/${t} activate"
162
- chmod +x " $WORKON_HOME /env1/bin/${t} activate"
163
- done
164
-
165
- rm " $test_dir /catch_output"
166
-
167
- workon env1
168
-
169
- output=$( cat " $test_dir /catch_output" )
170
- expected=" GLOBAL preactivate
171
- ENV preactivate
172
- GLOBAL postactivate
173
- ENV postactivate"
174
-
175
- assertSame " $expected " " $output "
176
-
177
- for t in pre post
178
- do
179
- rm -f " $WORKON_HOME /env1/bin/${t} activate"
180
- rm -f " $WORKON_HOME /${t} activate"
181
- done
182
- }
183
-
184
- test_deactivate () {
185
- workon env1
186
- assertNotNull " $VIRTUAL_ENV "
187
- deactivate
188
- assertNull " $VIRTUAL_ENV "
189
- assertFalse virtualenvwrapper_verify_active_environment
190
- }
191
-
192
- test_deactivate_hooks () {
193
- workon env1
194
-
195
- for t in pre post
196
- do
197
- echo " echo GLOBAL ${t} deactivate >> $test_dir /catch_output" > " $WORKON_HOME /${t} deactivate"
198
- echo " echo ENV ${t} deactivate >> $test_dir /catch_output" > " $WORKON_HOME /env1/bin/${t} deactivate"
199
- done
200
-
201
- deactivate
202
-
203
- output=$( cat " $test_dir /catch_output" )
204
- expected=" ENV predeactivate
205
- GLOBAL predeactivate
206
- ENV postdeactivate
207
- GLOBAL postdeactivate"
208
- assertSame " $expected " " $output "
209
-
210
- for t in pre post
211
- do
212
- rm -f " $WORKON_HOME /env1/bin/${t} activate"
213
- rm -f " $WORKON_HOME /${t} activate"
214
- done
215
- }
216
-
217
- test_virtualenvwrapper_show_workon_options () {
218
- mkdir " $WORKON_HOME /not_env"
219
- (cd " $WORKON_HOME " ; ln -s env1 link_env)
220
- envs=$( virtualenvwrapper_show_workon_options | tr ' \n' ' ' )
221
- assertSame " env1 env2 link_env " " $envs "
222
- rmdir " $WORKON_HOME /not_env"
223
- rm -f " $WORKON_HOME /link_env"
224
- }
225
-
226
- test_virtualenvwrapper_show_workon_options_no_envs () {
227
- old_home=" $WORKON_HOME "
228
- export WORKON_HOME=${TMPDIR:-/ tmp} /$$
229
- envs=$( virtualenvwrapper_show_workon_options 2> /dev/null | tr ' \n' ' ' )
230
- assertSame " " " $envs "
231
- export WORKON_HOME=" $old_home "
232
- }
233
-
234
- test_rmvirtualenv () {
235
- mkvirtualenv " deleteme"
236
- assertTrue " [ -d $WORKON_HOME /deleteme ]"
237
- deactivate
238
- rmvirtualenv " deleteme"
239
- assertFalse " [ -d $WORKON_HOME /deleteme ]"
240
- }
241
-
242
- test_rmvirtualenv_no_such_env () {
243
- assertFalse " [ -d $WORKON_HOME /deleteme ]"
244
- assertTrue " rmvirtualenv deleteme"
245
- }
246
-
247
- test_missing_workon_home () {
248
- save_home=" $WORKON_HOME "
249
- WORKON_HOME=" /tmp/NO_SUCH_WORKON_HOME"
250
- assertFalse " workon"
251
- assertFalse " mkvirtualenv foo"
252
- assertFalse " rmvirtualenv foo"
253
- assertFalse " lssitepackages"
254
- WORKON_HOME=" $save_home "
255
- }
256
-
257
- test_add2virtualenv () {
258
- mkvirtualenv " pathtest"
259
- add2virtualenv " /full/path"
260
- cdsitepackages
261
- path_file=" ./virtualenv_path_extensions.pth"
262
- assertTrue " No /full/path in ` cat $path_file ` " " grep /full/path $path_file "
263
- cd -
264
- }
265
-
266
- test_add2virtualenv_relative () {
267
- mkvirtualenv " pathtest"
268
- parent_dir=$( dirname $( pwd) )
269
- base_dir=$( basename $( pwd) )
270
- add2virtualenv " ../$base_dir "
271
- cdsitepackages
272
- path_file=" ./virtualenv_path_extensions.pth"
273
- assertTrue " No $parent_dir /$base_dir in \" ` cat $path_file ` \" " " grep \" $parent_dir /$base_dir \" $path_file "
274
- cd - > /dev/null 2>&1
275
- }
276
-
277
- test_lssitepackages () {
278
- mkvirtualenv " lssitepackagestest"
279
- contents=" $( lssitepackages) "
280
- assertTrue " No easy-install.pth in $contents " " echo $contents | grep easy-install.pth"
281
- }
282
-
283
- test_lssitepackages_add2virtualenv () {
284
- mkvirtualenv " lssitepackagestest"
285
- parent_dir=$( dirname $( pwd) )
286
- base_dir=$( basename $( pwd) )
287
- add2virtualenv " ../$base_dir "
288
- contents=" $( lssitepackages) "
289
- assertTrue " No $base_dir in $contents " " echo $contents | grep $base_dir "
290
- }
291
-
292
39
293
40
. " $test_dir /shunit2"
0 commit comments