Skip to content

Commit f03b4ef

Browse files
committed
Bypass the test for missing virtualenv if the user has it installed to the subset of the path needed for the shunit2 framework to function properly.
Add a test for having VIRTUALENVWRAPER_VIRTUALENV set to a program that does not exist.
1 parent 14989f8 commit f03b4ef

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

tests/test_mkvirtualenv.sh

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,18 @@ GLOBAL postmkvirtualenv"
5555
}
5656

5757
test_no_virtualenv () {
58+
# Find "which" before we change the path
59+
which=$(which which)
5860
old_path="$PATH"
5961
PATH="/bin:/usr/sbin:/sbin"
60-
assertFalse "Found virtualenv in $(which virtualenv)" "which virtualenv"
61-
mkvirtualenv should_not_be_created 2>/dev/null
62+
venv=$($which virtualenv 2>/dev/null)
63+
if [ ! -z "$venv" ]
64+
then
65+
echo "FOUND \"$venv\" in PATH so skipping this test"
66+
export PATH="$old_path"
67+
return 0
68+
fi
69+
mkvirtualenv should_not_be_created >/dev/null 2>&1
6270
RC=$?
6371
# Restore the path before testing because
6472
# the test script depends on commands in the
@@ -111,6 +119,25 @@ test_mkvirtualenv_args () {
111119
unset VIRTUALENVWRAPPER_VIRTUALENV_ARGS
112120
}
113121

122+
test_no_such_virtualenv () {
123+
VIRTUALENVWRAPPER_VIRTUALENV=/path/to/missing/program
124+
125+
echo "#!/bin/sh" > "$WORKON_HOME/premkvirtualenv"
126+
echo "echo GLOBAL premkvirtualenv \`pwd\` \"\$@\" >> \"$pre_test_dir/catch_output\"" >> "$WORKON_HOME/premkvirtualenv"
127+
chmod +x "$WORKON_HOME/premkvirtualenv"
128+
129+
echo "echo GLOBAL postmkvirtualenv >> $test_dir/catch_output" > "$WORKON_HOME/postmkvirtualenv"
130+
mkvirtualenv "env3" >/dev/null 2>&1
131+
output=$(cat "$test_dir/catch_output" 2>/dev/null)
132+
workon_home_as_pwd=$(cd $WORKON_HOME; pwd)
133+
expected=""
134+
assertSame "$expected" "$output"
135+
rm -f "$WORKON_HOME/premkvirtualenv"
136+
rm -f "$WORKON_HOME/postmkvirtualenv"
137+
138+
VIRTUALENVWRAPPER_VIRTUALENV=virtualenv
139+
}
140+
114141
test_virtualenv_fails () {
115142
# Test to reproduce the conditions in issue #76
116143
# https://bitbucket.org/dhellmann/virtualenvwrapper/issue/76/

0 commit comments

Comments
 (0)