Source

virtualenvwrapper / test.sh

#!/bin/sh

#set -x

export WORKON_HOME="./WORKON_HOME"
mkdir -p $WORKON_HOME

function mk_test_hook () {
    hookname="$1"
    echo "echo \"$hookname\" \$@" > $WORKON_HOME/$hookname
    chmod +x $WORKON_HOME/$hookname
}

mk_test_hook premkvirtualenv
mk_test_hook postmkvirtualenv
mk_test_hook prermvirtualenv
mk_test_hook postrmvirtualenv
mk_test_hook postactivate

echo
echo "HOOKS:"
ls -l $WORKON_HOME

bindir=$(dirname $0)
source "$bindir/virtualenvwrapper_bashrc"

echo
echo "CREATING AND ACTIVATING"
mkvirtualenv "env1"
echo "Current environment: $VIRTUAL_ENV"

echo
echo "NAVIGATION"
echo -n "remember where we start "
pushd `pwd`
cdvirtualenv
echo "cdvirtualenv: `pwd`"
cdsitepackages
echo "cdsitepackages: `pwd`"
echo -n "back to where we started "
popd

echo
echo "CREATING AND SWITCHING"
mkvirtualenv "env2"
echo "Current environment: $VIRTUAL_ENV"
echo -n "virtualenvwrapper_verify_active_environment: "
virtualenvwrapper_verify_active_environment && echo "PASS" || echo "FAIL"

echo
echo "POSTACTIVATE HOOK"
echo "echo postactivate" > $WORKON_HOME/env1/bin/postactivate
workon env1
echo -n "virtualenvwrapper_verify_active_environment: "
virtualenvwrapper_verify_active_environment && echo "PASS" || echo "FAIL"

echo
echo "DEACTIVATING"
deactivate
echo "VIRTUAL_ENV: $VIRTUAL_ENV"
echo "virtualenvwrapper_verify_active_environment: "
virtualenvwrapper_verify_active_environment && echo "FAIL" || echo "PASS"

echo
echo "LISTING ENVIRONMENTS"
envs=`workon | tr '\n' ' '`
echo "Found environments: $envs"
if [ "$envs" = "env1 env2 " ]
then
    echo "PASS"
else
    echo "FAIL: \""$envs\"""
fi

echo
echo "REMOVING ENVIRONMENTS"
rmvirtualenv "env1"
rmvirtualenv "env2"

rm -rf $WORKON_HOME

echo
echo "MISSING WORKON_HOME"
echo -n "workon: "
workon && echo "Failed to detect missing dir" || echo "PASS"
echo -n "mkvirtualenv: "
mkvirtualenv foo && echo "Failed to detect missing dir" || echo "PASS"
echo -n "rmvirtualenv: "
rmvirtualenv foo && echo "Failed to detect missing dir" || echo "PASS"
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.