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