Doug Hellmann avatar Doug Hellmann committed 34c5c4e

fix #26 by quieting the error message during init and only showing it when an action is explicitly taken by the user

Comments (0)

Files changed (8)

     done
 }
 
+test_virtualenvwrapper_verify_workon_home() {
+    assertTrue "WORKON_HOME not verified" virtualenvwrapper_verify_workon_home
+}
+
+test_virtualenvwrapper_verify_workon_home_missing_dir() {
+    old_home="$WORKON_HOME"
+    WORKON_HOME="$WORKON_HOME/not_there"
+    assertFalse "WORKON_HOME verified unexpectedly" virtualenvwrapper_verify_workon_home
+    WORKON_HOME="$old_home"
+}
+
+test_virtualenvwrapper_verify_workon_home_missing_dir_quiet_init() {
+    old_home="$WORKON_HOME"
+    export WORKON_HOME="$WORKON_HOME/not_there"
+    output=`$SHELL $test_dir/../virtualenvwrapper_bashrc 2>&1`
+    assertSame "" "$output"
+    WORKON_HOME="$old_home"
+}
+
 test_get_python_version() {
     expected=$(python -V 2>&1 | cut -f2 -d' ' | cut -f-2 -d.)
     actual=$(virtualenvwrapper_get_python_version)
     popd >/dev/null
 }
 
+test_cdvirtualenv_no_workon_home () {
+    old_home="$WORKON_HOME"
+    export WORKON_HOME="$WORKON_HOME/not_there"
+    output=`cdvirtualenv 2>&1`
+    assertTrue "Did not see expected message" "echo $output | grep 'does not exist'"
+    WORKON_HOME="$old_home"
+}
+
+test_cdsitepackages_no_workon_home () {
+    old_home="$WORKON_HOME"
+    export WORKON_HOME="$WORKON_HOME/not_there"
+    output=`cdsitepackages 2>&1`
+    assertTrue "Did not see expected message" "echo $output | grep 'does not exist'"
+    WORKON_HOME="$old_home"
+}
+
 
 . "$test_dir/shunit2"
     assertTrue "No $base_dir in $contents" "echo $contents | grep $base_dir"
 }
 
+test_no_workon_home () {
+    old_home="$WORKON_HOME"
+    export WORKON_HOME="$WORKON_HOME/not_there"
+    output=`lssitepackages should_not_be_created 2>&1`
+    assertTrue "Did not see expected message" "echo $output | grep 'does not exist'"
+    WORKON_HOME="$old_home"
+}
+
 
 . "$test_dir/shunit2"

tests/test_misconfigured.sh

-#!/bin/sh
-
-#set -x
-
-test_dir=$(dirname $0)
-
-export SCRATCH_DIR="${TMPDIR:-/tmp}/$$"
-
-oneTimeSetUp() {
-    rm -rf "$SCRATCH_DIR"
-    mkdir -p "$SCRATCH_DIR"
-}
-
-oneTimeTearDown() {
-    rm -rf "$SCRATCH_DIR"
-}
-
-test_workon_home_missing_bash () {
-    export WORKON_HOME="$SCRATCH_DIR/no_such_subdir"
-    bash -ec "source $test_dir/../virtualenvwrapper_bashrc" 2>/dev/null
-    RC=$?
-    assertSame "1" "$RC"
-}
-
-test_workon_home_missing_zsh () {
-    export WORKON_HOME="$SCRATCH_DIR/no_such_subdir"
-    zsh -ec "source $test_dir/../virtualenvwrapper_bashrc" 2>/dev/null
-    RC=$?
-    assertSame "1" "$RC"
-}
-
-test_shell_expansion_fails_bash () {
-    export WORKON_HOME="$SCRATCH_DIR/\$no_such_var"
-    bash -ec "source $test_dir/../virtualenvwrapper_bashrc" 2>/dev/null
-    RC=$?
-    assertSame "1" "$RC"
-}
-
-test_shell_expansion_fails_zsh () {
-    export WORKON_HOME="$SCRATCH_DIR/\$no_such_var"
-    zsh -ec "source $test_dir/../virtualenvwrapper_bashrc" 2>/dev/null
-    RC=$?
-    assertSame "1" "$RC"
-}
-
-. "$test_dir/shunit2"

tests/test_mkvirtualenv.sh

     rm -f "$test_dir/catch_output"
 }
 
-test_mkvirtualenv() {
+test_create() {
     mkvirtualenv "env1"
     assertTrue "Environment directory was not created" "[ -d $WORKON_HOME/env1 ]"
     for hook in postactivate predeactivate postdeactivate
     done
 }
 
-test_mkvirtualenv_activates () {
+test_activates () {
     mkvirtualenv "env2"
     assertTrue virtualenvwrapper_verify_active_environment
     assertSame "env2" $(basename "$VIRTUAL_ENV")
 }
 
-test_mkvirtualenv_hooks () {
+test_hooks () {
     export pre_test_dir=$(cd "$test_dir"; pwd)
     echo "echo GLOBAL premkvirtualenv >> \"$pre_test_dir/catch_output\"" >> "$WORKON_HOME/premkvirtualenv"
     chmod +x "$WORKON_HOME/premkvirtualenv"
     assertSame "$RC" "1"
 }
 
+test_no_workon_home () {
+    old_home="$WORKON_HOME"
+    export WORKON_HOME="$WORKON_HOME/not_there"
+    output=`mkvirtualenv should_not_be_created 2>&1`
+    assertTrue "Did not see expected message" "echo $output | grep 'does not exist'"
+    WORKON_HOME="$old_home"
+}
+
 # test_mkvirtualenv_sitepackages () {
 #     # Without the option verify that site-packages are copied.
 #     mkvirtualenv "env3"

tests/test_rmvirtualenv.sh

     rm -f "$test_dir/catch_output"
 }
 
-test_rmvirtualenv () {
+test_remove () {
     mkvirtualenv "deleteme"
     assertTrue "[ -d $WORKON_HOME/deleteme ]"
     deactivate
     assertFalse "[ -d $WORKON_HOME/deleteme ]"
 }
 
-test_rmvirtualenv_no_such_env () {
+test_no_such_env () {
     assertFalse "[ -d $WORKON_HOME/deleteme ]"
     assertTrue "rmvirtualenv deleteme"
 }
 
-test_add2virtualenv () {
-    mkvirtualenv "pathtest"
-    add2virtualenv "/full/path"
-    cdsitepackages
-    path_file="./virtualenv_path_extensions.pth"
-    assertTrue "No /full/path in `cat $path_file`" "grep /full/path $path_file"
-    cd -
+test_no_workon_home () {
+    old_home="$WORKON_HOME"
+    export WORKON_HOME="$WORKON_HOME/not_there"
+    output=`rmvirtualenv should_not_be_created 2>&1`
+    assertTrue "Did not see expected message" "echo $output | grep 'does not exist'"
+    WORKON_HOME="$old_home"
 }
 
-test_add2virtualenv_relative () {
-    mkvirtualenv "pathtest"
-    parent_dir=$(dirname $(pwd))
-    base_dir=$(basename $(pwd))
-    add2virtualenv "../$base_dir"
-    cdsitepackages
-    path_file="./virtualenv_path_extensions.pth"
-    assertTrue "No $parent_dir/$base_dir in \"`cat $path_file`\"" "grep \"$parent_dir/$base_dir\" $path_file"
-    cd - >/dev/null 2>&1
-}
-
-test_lssitepackages () {
-    mkvirtualenv "lssitepackagestest"
-    contents="$(lssitepackages)"    
-    assertTrue "No easy-install.pth in $contents" "echo $contents | grep easy-install.pth"
-}
-
-test_lssitepackages_add2virtualenv () {
-    mkvirtualenv "lssitepackagestest"
-    parent_dir=$(dirname $(pwd))
-    base_dir=$(basename $(pwd))
-    add2virtualenv "../$base_dir"
-    contents="$(lssitepackages)"    
-    assertTrue "No $base_dir in $contents" "echo $contents | grep $base_dir"
-}
-
 
 . "$test_dir/shunit2"

tests/test_workon.sh

     export WORKON_HOME="$old_home"
 }
 
-test_missing_workon_home () {
-    save_home="$WORKON_HOME"
-    WORKON_HOME="/tmp/NO_SUCH_WORKON_HOME"
-    assertFalse "workon"
-    assertFalse "mkvirtualenv foo"
-    assertFalse "rmvirtualenv foo"
-    assertFalse "lssitepackages"
-    WORKON_HOME="$save_home"
+test_no_workon_home () {
+    old_home="$WORKON_HOME"
+    export WORKON_HOME="$WORKON_HOME/not_there"
+    output=`workon should_not_be_created 2>&1`
+    assertTrue "Did not see expected message" "echo $output | grep 'does not exist'"
+    WORKON_HOME="$old_home"
 }
 
 . "$test_dir/shunit2"

virtualenvwrapper_bashrc

 function virtualenvwrapper_verify_workon_home () {
     if [ ! -d "$WORKON_HOME" ]
     then
-        echo "ERROR: Virtual environments directory '$WORKON_HOME' does not exist." >&2
+        [ "$1" != "-q" ] && echo "ERROR: Virtual environments directory '$WORKON_HOME' does not exist.  Create it or set WORKON_HOME to an existing directory." >&2
         return 1
     fi
     return 0
 
 # Set up virtualenvwrapper properly
 function virtualenvwrapper_initialize () {
-    virtualenvwrapper_verify_workon_home || return 1
+    virtualenvwrapper_verify_workon_home -q || return 1
     # mkvirtualenv
     virtualenvwrapper_make_hook "$WORKON_HOME/premkvirtualenv" \
         "This hook is run after a new virtualenv is created and before it is activated."
 # created first.
 function add2virtualenv () {
 
+    virtualenvwrapper_verify_workon_home || return 1
     virtualenvwrapper_verify_active_environment || return 1
     
     site_packages="`virtualenvwrapper_get_site_packages_dir`"
 # Does a ``cd`` to the site-packages directory of the currently-active
 # virtualenv.
 function cdsitepackages () {
+    virtualenvwrapper_verify_workon_home || return 1
     virtualenvwrapper_verify_active_environment || return 1
     site_packages="`virtualenvwrapper_get_site_packages_dir`"
     cd "$site_packages"/$1
 
 # Does a ``cd`` to the root of the currently-active virtualenv.
 function cdvirtualenv () {
+    virtualenvwrapper_verify_workon_home || return 1
     virtualenvwrapper_verify_active_environment || return 1
     cd $VIRTUAL_ENV/$1
 }
 # Shows the content of the site-packages directory of the currently-active
 # virtualenv
 function lssitepackages () {
+    virtualenvwrapper_verify_workon_home || return 1
     virtualenvwrapper_verify_active_environment || return 1
     site_packages="`virtualenvwrapper_get_site_packages_dir`"
     ls $@ $site_packages
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.