Skip to content

Commit 0f80303

Browse files
committedMar 20, 2010
fix #26 by quieting the error message during init and only showing it when an action is explicitly taken by the user
1 parent 853b000 commit 0f80303

8 files changed

+74
-94
lines changed
 

‎tests/test.sh

+19
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,25 @@ test_virtualenvwrapper_initialize() {
3030
done
3131
}
3232

33+
test_virtualenvwrapper_verify_workon_home() {
34+
assertTrue "WORKON_HOME not verified" virtualenvwrapper_verify_workon_home
35+
}
36+
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"
50+
}
51+
3352
test_get_python_version() {
3453
expected=$(python -V 2>&1 | cut -f2 -d' ' | cut -f-2 -d.)
3554
actual=$(virtualenvwrapper_get_python_version)

‎tests/test_cd.sh

+16
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,21 @@ test_cdsitepackages_with_arg () {
4949
popd >/dev/null
5050
}
5151

52+
test_cdvirtualenv_no_workon_home () {
53+
old_home="$WORKON_HOME"
54+
export WORKON_HOME="$WORKON_HOME/not_there"
55+
output=`cdvirtualenv 2>&1`
56+
assertTrue "Did not see expected message" "echo $output | grep 'does not exist'"
57+
WORKON_HOME="$old_home"
58+
}
59+
60+
test_cdsitepackages_no_workon_home () {
61+
old_home="$WORKON_HOME"
62+
export WORKON_HOME="$WORKON_HOME/not_there"
63+
output=`cdsitepackages 2>&1`
64+
assertTrue "Did not see expected message" "echo $output | grep 'does not exist'"
65+
WORKON_HOME="$old_home"
66+
}
67+
5268

5369
. "$test_dir/shunit2"

‎tests/test_ls.sh

+8
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,13 @@ test_lssitepackages_add2virtualenv () {
3636
assertTrue "No $base_dir in $contents" "echo $contents | grep $base_dir"
3737
}
3838

39+
test_no_workon_home () {
40+
old_home="$WORKON_HOME"
41+
export WORKON_HOME="$WORKON_HOME/not_there"
42+
output=`lssitepackages should_not_be_created 2>&1`
43+
assertTrue "Did not see expected message" "echo $output | grep 'does not exist'"
44+
WORKON_HOME="$old_home"
45+
}
46+
3947

4048
. "$test_dir/shunit2"

‎tests/test_misconfigured.sh

-46
This file was deleted.

‎tests/test_mkvirtualenv.sh

+11-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ setUp () {
2121
rm -f "$test_dir/catch_output"
2222
}
2323

24-
test_mkvirtualenv() {
24+
test_create() {
2525
mkvirtualenv "env1"
2626
assertTrue "Environment directory was not created" "[ -d $WORKON_HOME/env1 ]"
2727
for hook in postactivate predeactivate postdeactivate
@@ -31,13 +31,13 @@ test_mkvirtualenv() {
3131
done
3232
}
3333

34-
test_mkvirtualenv_activates () {
34+
test_activates () {
3535
mkvirtualenv "env2"
3636
assertTrue virtualenvwrapper_verify_active_environment
3737
assertSame "env2" $(basename "$VIRTUAL_ENV")
3838
}
3939

40-
test_mkvirtualenv_hooks () {
40+
test_hooks () {
4141
export pre_test_dir=$(cd "$test_dir"; pwd)
4242
echo "echo GLOBAL premkvirtualenv >> \"$pre_test_dir/catch_output\"" >> "$WORKON_HOME/premkvirtualenv"
4343
chmod +x "$WORKON_HOME/premkvirtualenv"
@@ -65,6 +65,14 @@ test_no_virtualenv () {
6565
assertSame "$RC" "1"
6666
}
6767

68+
test_no_workon_home () {
69+
old_home="$WORKON_HOME"
70+
export WORKON_HOME="$WORKON_HOME/not_there"
71+
output=`mkvirtualenv should_not_be_created 2>&1`
72+
assertTrue "Did not see expected message" "echo $output | grep 'does not exist'"
73+
WORKON_HOME="$old_home"
74+
}
75+
6876
# test_mkvirtualenv_sitepackages () {
6977
# # Without the option verify that site-packages are copied.
7078
# mkvirtualenv "env3"

‎tests/test_rmvirtualenv.sh

+8-35
Original file line numberDiff line numberDiff line change
@@ -21,52 +21,25 @@ setUp () {
2121
rm -f "$test_dir/catch_output"
2222
}
2323

24-
test_rmvirtualenv () {
24+
test_remove () {
2525
mkvirtualenv "deleteme"
2626
assertTrue "[ -d $WORKON_HOME/deleteme ]"
2727
deactivate
2828
rmvirtualenv "deleteme"
2929
assertFalse "[ -d $WORKON_HOME/deleteme ]"
3030
}
3131

32-
test_rmvirtualenv_no_such_env () {
32+
test_no_such_env () {
3333
assertFalse "[ -d $WORKON_HOME/deleteme ]"
3434
assertTrue "rmvirtualenv deleteme"
3535
}
3636

37-
test_add2virtualenv () {
38-
mkvirtualenv "pathtest"
39-
add2virtualenv "/full/path"
40-
cdsitepackages
41-
path_file="./virtualenv_path_extensions.pth"
42-
assertTrue "No /full/path in `cat $path_file`" "grep /full/path $path_file"
43-
cd -
44-
}
45-
46-
test_add2virtualenv_relative () {
47-
mkvirtualenv "pathtest"
48-
parent_dir=$(dirname $(pwd))
49-
base_dir=$(basename $(pwd))
50-
add2virtualenv "../$base_dir"
51-
cdsitepackages
52-
path_file="./virtualenv_path_extensions.pth"
53-
assertTrue "No $parent_dir/$base_dir in \"`cat $path_file`\"" "grep \"$parent_dir/$base_dir\" $path_file"
54-
cd - >/dev/null 2>&1
55-
}
56-
57-
test_lssitepackages () {
58-
mkvirtualenv "lssitepackagestest"
59-
contents="$(lssitepackages)"
60-
assertTrue "No easy-install.pth in $contents" "echo $contents | grep easy-install.pth"
61-
}
62-
63-
test_lssitepackages_add2virtualenv () {
64-
mkvirtualenv "lssitepackagestest"
65-
parent_dir=$(dirname $(pwd))
66-
base_dir=$(basename $(pwd))
67-
add2virtualenv "../$base_dir"
68-
contents="$(lssitepackages)"
69-
assertTrue "No $base_dir in $contents" "echo $contents | grep $base_dir"
37+
test_no_workon_home () {
38+
old_home="$WORKON_HOME"
39+
export WORKON_HOME="$WORKON_HOME/not_there"
40+
output=`rmvirtualenv should_not_be_created 2>&1`
41+
assertTrue "Did not see expected message" "echo $output | grep 'does not exist'"
42+
WORKON_HOME="$old_home"
7043
}
7144

7245

‎tests/test_workon.sh

+6-8
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,12 @@ test_virtualenvwrapper_show_workon_options_no_envs () {
106106
export WORKON_HOME="$old_home"
107107
}
108108

109-
test_missing_workon_home () {
110-
save_home="$WORKON_HOME"
111-
WORKON_HOME="/tmp/NO_SUCH_WORKON_HOME"
112-
assertFalse "workon"
113-
assertFalse "mkvirtualenv foo"
114-
assertFalse "rmvirtualenv foo"
115-
assertFalse "lssitepackages"
116-
WORKON_HOME="$save_home"
109+
test_no_workon_home () {
110+
old_home="$WORKON_HOME"
111+
export WORKON_HOME="$WORKON_HOME/not_there"
112+
output=`workon should_not_be_created 2>&1`
113+
assertTrue "Did not see expected message" "echo $output | grep 'does not exist'"
114+
WORKON_HOME="$old_home"
117115
}
118116

119117
. "$test_dir/shunit2"

‎virtualenvwrapper_bashrc

+6-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export WORKON_HOME
6060
function virtualenvwrapper_verify_workon_home () {
6161
if [ ! -d "$WORKON_HOME" ]
6262
then
63-
echo "ERROR: Virtual environments directory '$WORKON_HOME' does not exist." >&2
63+
[ "$1" != "-q" ] && echo "ERROR: Virtual environments directory '$WORKON_HOME' does not exist. Create it or set WORKON_HOME to an existing directory." >&2
6464
return 1
6565
fi
6666
return 0
@@ -90,7 +90,7 @@ EOF
9090

9191
# Set up virtualenvwrapper properly
9292
function virtualenvwrapper_initialize () {
93-
virtualenvwrapper_verify_workon_home || return 1
93+
virtualenvwrapper_verify_workon_home -q || return 1
9494
# mkvirtualenv
9595
virtualenvwrapper_make_hook "$WORKON_HOME/premkvirtualenv" \
9696
"This hook is run after a new virtualenv is created and before it is activated."
@@ -352,6 +352,7 @@ function virtualenvwrapper_get_site_packages_dir () {
352352
# created first.
353353
function add2virtualenv () {
354354

355+
virtualenvwrapper_verify_workon_home || return 1
355356
virtualenvwrapper_verify_active_environment || return 1
356357

357358
site_packages="`virtualenvwrapper_get_site_packages_dir`"
@@ -392,20 +393,23 @@ function add2virtualenv () {
392393
# Does a ``cd`` to the site-packages directory of the currently-active
393394
# virtualenv.
394395
function cdsitepackages () {
396+
virtualenvwrapper_verify_workon_home || return 1
395397
virtualenvwrapper_verify_active_environment || return 1
396398
site_packages="`virtualenvwrapper_get_site_packages_dir`"
397399
cd "$site_packages"/$1
398400
}
399401

400402
# Does a ``cd`` to the root of the currently-active virtualenv.
401403
function cdvirtualenv () {
404+
virtualenvwrapper_verify_workon_home || return 1
402405
virtualenvwrapper_verify_active_environment || return 1
403406
cd $VIRTUAL_ENV/$1
404407
}
405408

406409
# Shows the content of the site-packages directory of the currently-active
407410
# virtualenv
408411
function lssitepackages () {
412+
virtualenvwrapper_verify_workon_home || return 1
409413
virtualenvwrapper_verify_active_environment || return 1
410414
site_packages="`virtualenvwrapper_get_site_packages_dir`"
411415
ls $@ $site_packages

0 commit comments

Comments
 (0)
Please sign in to comment.