Doug Hellmann avatar Doug Hellmann committed c11ee79

verify that virtualenv is installed; correct use of python to fix the WORKON_HOME value; more tests

Comments (0)

Files changed (4)

     sh('bash ./tests/test.sh')
     sh('SHUNIT_PARENT=./tests/test.sh zsh -o shwordsplit ./tests/test.sh')
     sh('bash ./tests/test_misconfigured.sh')
-    sh('SHUNIT_PARENT=./tests/test_misconfigured.sh zsh -o shwordsplit ./tests/test.sh')
     return
     assertSame "env2" $(basename "$VIRTUAL_ENV")
 }
 
+test_no_virtualenv () {
+    old_path="$PATH"
+    PATH="/usr/bin:/usr/local/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$HOME/bin"
+    mkvirtualenv should_not_be_created # 2>/dev/null
+    RC=$?
+    # Restore the path before testing because
+    # the test script depends on commands in the
+    # path.
+    export PATH="$old_path"
+    assertSame "$RC" "1"
+}
+
 # test_mkvirtualenv_sitepackages () {
 #     # Without the option verify that site-packages are copied.
 #     mkvirtualenv "env3"
 
 test_virtualenvwrapper_show_workon_options_no_envs () {
     old_home="$WORKON_HOME"
-    export WORKON_HOME=${TMPDIR:/tmp}/$$
-    envs=$(virtualenvwrapper_show_workon_options | tr '\n' ' ')
+    export WORKON_HOME=${TMPDIR:-/tmp}/$$
+    envs=$(virtualenvwrapper_show_workon_options 2>/dev/null | tr '\n' ' ')
     assertSame "" "$envs"
     export WORKON_HOME="$old_home"
 }

tests/test_misconfigured.sh

     rm -rf "$SCRATCH_DIR"
 }
 
-test_workon_home_missing () {
+test_workon_home_missing_bash () {
     export WORKON_HOME="$SCRATCH_DIR/no_such_subdir"
-    $SHELL -ec "source $test_dir/../virtualenvwrapper_bashrc" 2>/dev/null
+    bash -ec "source $test_dir/../virtualenvwrapper_bashrc" 2>/dev/null
     RC=$?
     assertSame "1" "$RC"
 }
 
-test_shell_expansion_fails () {
+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"
-    $SHELL -ec "source $test_dir/../virtualenvwrapper_bashrc" 2>/dev/null
+    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"
 }

virtualenvwrapper_bashrc

 
 # Normalize the directory name in case it includes 
 # relative path components.
-WORKON_HOME=$(python -c "import os; print os.path.abspath(os.path.expandshell(os.path.expanduser(\"$pydir\")))")
+WORKON_HOME=$(python -c "import os; print os.path.abspath(os.path.expandvars(os.path.expanduser(\"$WORKON_HOME\")))")
 export WORKON_HOME
 
 # Verify that the WORKON_HOME directory exists
 
 virtualenvwrapper_verify_workon_home
 
+# Verify that virtualenv is installed and visible
+function virtualenvwrapper_verify_virtualenv () {
+    venv=$(which virtualenv | grep -v "not found")
+    if [ "$venv" = "" ]
+    then
+        echo "ERROR: virtualenvwrapper could not find virtualenv in your path" >&2
+        return 1
+    fi
+    if [ ! -e "$venv" ]
+    then
+        echo "ERROR: Found virtualenv in path as \"$venv\" but that does not exist" >&2
+        return 1
+    fi
+    return 0
+}
+
 # Verify that the requested environment exists
 function virtualenvwrapper_verify_workon_environment () {
     typeset env_name="$1"
 function mkvirtualenv () {
     eval "envname=\$$#"
     virtualenvwrapper_verify_workon_home || return 1
+    virtualenvwrapper_verify_virtualenv || return 1
     (cd "$WORKON_HOME" &&
         virtualenv "$@" &&
         virtualenvwrapper_run_hook "./premkvirtualenv" "$envname"
     # NOTE: DO NOT use ls here because colorized versions spew control characters
     #       into the output list.
     # echo seems a little faster than find, even with -depth 3.
-    (cd "$WORKON_HOME"; for f in */bin/activate; do echo $f; done) | sed 's|^\./||' | sed 's|/bin/activate||' | sort
+    (cd "$WORKON_HOME"; for f in */bin/activate; do echo $f; done) 2>/dev/null | sed 's|^\./||' | sed 's|/bin/activate||' | sort
 #    (cd "$WORKON_HOME"; find -L . -depth 3 -path '*/bin/activate') | sed 's|^\./||' | sed 's|/bin/activate||' | sort
 }
 
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.