Skip to content

Commit da7117a

Browse files
committed
fix tests; clean up contributed changes
1 parent c673ab4 commit da7117a

File tree

7 files changed

+56
-36
lines changed

7 files changed

+56
-36
lines changed

ChangeLog

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
2010-05-09 Doug Hellmann <[email protected]>
2+
3+
* virtualenvwrapper.sh: Tweak path normalization code so double
4+
slashes are also removed from WORKON_HOME. Use typeset for local
5+
variables.
6+
(virtualenvwrapper_tempfile): Add -t option to mktemp so the new
7+
files are always created in the user's temporary directory.
8+
(virtualenvwrapper_run_hook): Add the hook name to the temporary
9+
file name.
10+
11+
* tests/test_tempfile.sh: Remove obsolete test. Fix assertions
12+
for remaining test.
13+
14+
* tests/test_mkvirtualenv.sh (test_hooks): Use pwd to convert
15+
WORKON_HOME to the expected value.
16+
17+
* tests/test.sh (test_python_interpreter_set_incorrectly): Rework
18+
grep-based assertion to actually pass.
19+
20+
* Makefile (test-bash test-ksh test-sh): Remove wildcard build
21+
rule so test-quick target works.
22+
123
2010-05-02 Doug Hellmann <[email protected]>
224

325
* virtualenvwrapper.sh (virtualenvwrapper_run_hook): Instead of

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ help:
2525
@echo "installwebsite - deploy web version of docs"
2626
@echo "develop - install development version"
2727
@echo "test - run the test suite"
28+
@echo "test-quick - run the test suite for bash and one version of Python"
2829

2930

3031
.PHONY: sdist
@@ -73,7 +74,7 @@ test:
7374
develop:
7475
python setup.py develop
7576

76-
test-%:
77+
test-bash test-ksh test-sh:
7778
TEST_SHELL=$(subst test-,,$@) $(MAKE) test-loop
7879

7980
test-zsh:
@@ -89,16 +90,17 @@ test-loop:
8990
&& virtualenv -p $$py_bin --no-site-packages virtualenvwrapper-test-env) \
9091
|| exit 1 ; \
9192
$$TMPDIR/virtualenvwrapper-test-env/bin/python setup.py install || exit 1 ; \
92-
for test_script in $(wildcard tests/test*.sh) ; do \
93+
for test_script in tests/test*.sh ; do \
9394
echo ; \
9495
echo '********************************************************************************' ; \
9596
echo "Running $$test_script with $(TEST_SHELL) under Python $(basename $$py_bin)" ; \
97+
echo ; \
9698
VIRTUALENVWRAPPER_PYTHON=$$TMPDIR/virtualenvwrapper-test-env/bin/python SHUNIT_PARENT=$$test_script $(TEST_SHELL) $$test_script || exit 1 ; \
9799
echo ; \
98100
done \
99101
done
100102

101-
test-quick: test-26
103+
test-quick:: test-26
102104

103105
test-24:
104106
PYTHON_BINARIES=$(PYTHON24) $(MAKE) test-bash

tests/test.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ test_python_interpreter_set_incorrectly() {
6767
return_to="$(pwd)"
6868
cd "$WORKON_HOME"
6969
mkvirtualenv --no-site-packages no_wrappers
70-
output=`VIRTUALENVWRAPPER_PYTHON=$VIRTUAL_ENV/bin/python $SHELL $return_to/virtualenvwrapper.sh 2>&1`
71-
assertTrue "Unexpected message: $output" "echo \"$output\" | grep 'Could not find Python module virtualenvwrapper.hook_loader'"
70+
expected="ImportError: No module named virtualenvwrapper.hook_loader"
71+
output=$(VIRTUALENVWRAPPER_PYTHON=$VIRTUAL_ENV/bin/python $SHELL $return_to/virtualenvwrapper.sh 2>&1)
72+
echo "$output" | grep "$expected" 2>&1
73+
found=$?
74+
assertTrue "Expected \"$expected\", got: \"$output\"" "[ $found -eq 0 ]"
7275
assertFalse "Failed to detect invalid Python location" "VIRTUALENVWRAPPER_PYTHON=$VIRTUAL_ENV/bin/python $SHELL $return_to/virtualenvwrapper.sh >/dev/null 2>&1"
7376
cd "$return_to"
7477
deactivate

tests/test_cp.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ test_hooks () {
6868
cpvirtualenv "source" "destination"
6969

7070
output=$(cat "$test_dir/catch_output")
71+
workon_home_as_pwd=$(cd $WORKON_HOME; pwd)
7172

72-
expected="GLOBAL precpvirtualenv $WORKON_HOME source destination
73-
GLOBAL premkvirtualenv $WORKON_HOME destination
73+
expected="GLOBAL precpvirtualenv $workon_home_as_pwd source destination
74+
GLOBAL premkvirtualenv $workon_home_as_pwd destination
7475
GLOBAL postmkvirtualenv
7576
GLOBAL postcpvirtualenv"
7677

tests/test_mkvirtualenv.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ test_hooks () {
4343
echo "echo GLOBAL postmkvirtualenv >> $test_dir/catch_output" > "$WORKON_HOME/postmkvirtualenv"
4444
mkvirtualenv "env3"
4545
output=$(cat "$test_dir/catch_output")
46-
expected="GLOBAL premkvirtualenv $WORKON_HOME env3
46+
workon_home_as_pwd=$(cd $WORKON_HOME; pwd)
47+
expected="GLOBAL premkvirtualenv $workon_home_as_pwd env3
4748
GLOBAL postmkvirtualenv"
4849
assertSame "$expected" "$output"
4950
rm -f "$WORKON_HOME/premkvirtualenv"

tests/test_tempfile.sh

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,8 @@ setUp () {
2525
test_tempfile () {
2626
filename=$(virtualenvwrapper_tempfile hook)
2727
rm -f $filename
28-
assertSame "$TMPDIR" "$(dirname $filename)/"
29-
assertTrue "echo $filename | grep virtualenvwrapper"
30-
}
31-
32-
test_no_python () {
33-
old=$VIRTUALENVWRAPPER_PYTHON
34-
VIRTUALENVWRAPPER_PYTHON=false
35-
filename=$(virtualenvwrapper_tempfile hook)
36-
VIRTUALENVWRAPPER_PYTHON=$old
37-
rm -f $filename
3828
assertSame "TMPDIR and path not the same for $filename." "$TMPDIR" "$(dirname $filename)/"
39-
assertTrue "virtualenvwrapper and pid not in filename." "echo $filename | grep virtualenvwrapper.$$"
29+
assertTrue "virtualenvwrapper-hook not in filename." "echo $filename | grep virtualenvwrapper-hook"
4030
}
4131

4232
. "$test_dir/shunit2"

virtualenvwrapper.sh

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ fi
6868
# path might contain stuff to expand.
6969
# (it might be possible to do this in shell, but I don't know a
7070
# cross-shell-safe way of doing it -wolever)
71-
if echo "$WORKON_HOME" | grep -e "[$~]" > /dev/null
71+
if echo "$WORKON_HOME" | egrep -e "([$~]|//)" >/dev/null
7272
then
7373
# This will normalize the path by:
74-
# - Expanding variables (eg, $foo)
75-
# - Converting ~s to complete paths (eg, ~/ to /home/brian/ and ~arthur to /home/arthur)
74+
# - Removing extra slashes (e.g., when TMPDIR ends in a slash)
75+
# - Expanding variables (e.g., $foo)
76+
# - Converting ~s to complete paths (e.g., ~/ to /home/brian/ and ~arthur to /home/arthur)
7677
WORKON_HOME=$("$VIRTUALENVWRAPPER_PYTHON" -c "import os; print os.path.expandvars(os.path.expanduser(\"$WORKON_HOME\"))")
7778
export WORKON_HOME
7879
fi
@@ -81,7 +82,7 @@ fi
8182
virtualenvwrapper_verify_workon_home () {
8283
if [ ! -d "$WORKON_HOME" ]
8384
then
84-
[ "$1" != "-q" ] && echo "ERROR: Virtual environments directory '$WORKON_HOME' does not exist. Create it or set WORKON_HOME to an existing directory." >&2
85+
[ "$1" != "-q" ] && echo "ERROR: Virtual environments directory '$WORKON_HOME' does not exist. Create it or set WORKON_HOME to an existing directory." 1>&2
8586
return 1
8687
fi
8788
return 0
@@ -92,20 +93,20 @@ virtualenvwrapper_verify_workon_home () {
9293
# Expects 1 argument, the suffix for the new file.
9394
virtualenvwrapper_tempfile () {
9495
# Note: the 'X's must come last
95-
mktemp "virtualenvwrapper-$1-XXXXXX"
96+
mktemp -t "virtualenvwrapper-$1-XXXXXX"
9697
}
9798

9899
# Run the hooks
99100
virtualenvwrapper_run_hook () {
100-
hook_script="$(virtualenvwrapper_tempfile hook)"
101+
typeset hook_script="$(virtualenvwrapper_tempfile ${1}-hook)"
101102
"$VIRTUALENVWRAPPER_PYTHON" -c 'from virtualenvwrapper.hook_loader import main; main()' $HOOK_VERBOSE_OPTION --script "$hook_script" "$@"
102103
result=$?
103104

104105
if [ $result -eq 0 ]
105106
then
106107
source "$hook_script"
107108
fi
108-
rm -f "$hook_script" &> /dev/null
109+
rm -f "$hook_script" >/dev/null 2>&1
109110
return $result
110111
}
111112

@@ -115,14 +116,14 @@ virtualenvwrapper_initialize () {
115116
virtualenvwrapper_run_hook "initialize"
116117
if [ $? -ne 0 ]
117118
then
118-
echo "virtualenvwrapper.sh: Python encountered a problem. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON and that PATH set properly." 1>&2
119+
echo "virtualenvwrapper.sh: Python encountered a problem. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON and that PATH is set properly." 1>&2
119120
return 1
120121
fi
121122
}
122123

123124
# Verify that virtualenv is installed and visible
124125
virtualenvwrapper_verify_virtualenv () {
125-
venv=$(which virtualenv | grep -v "not found")
126+
typeset venv=$(which virtualenv | grep -v "not found")
126127
if [ "$venv" = "" ]
127128
then
128129
echo "ERROR: virtualenvwrapper could not find virtualenv in your path" >&2
@@ -382,7 +383,7 @@ add2virtualenv () {
382383
cdsitepackages () {
383384
virtualenvwrapper_verify_workon_home || return 1
384385
virtualenvwrapper_verify_active_environment || return 1
385-
site_packages="`virtualenvwrapper_get_site_packages_dir`"
386+
typeset site_packages="`virtualenvwrapper_get_site_packages_dir`"
386387
cd "$site_packages"/$1
387388
}
388389

@@ -398,7 +399,7 @@ cdvirtualenv () {
398399
lssitepackages () {
399400
virtualenvwrapper_verify_workon_home || return 1
400401
virtualenvwrapper_verify_active_environment || return 1
401-
site_packages="`virtualenvwrapper_get_site_packages_dir`"
402+
typeset site_packages="`virtualenvwrapper_get_site_packages_dir`"
402403
ls $@ $site_packages
403404

404405
path_file="$site_packages/virtualenv_path_extensions.pth"
@@ -427,12 +428,12 @@ cpvirtualenv() {
427428
fi
428429
if echo "$WORKON_HOME" | grep -e "/$" > /dev/null
429430
then
430-
env_home="$WORKON_HOME"
431+
typset env_home="$WORKON_HOME"
431432
else
432-
env_home="$WORKON_HOME/"
433+
typeset env_home="$WORKON_HOME/"
433434
fi
434-
source_env="$env_home$env_name"
435-
target_env="$env_home$new_env"
435+
typeset source_env="$env_home$env_name"
436+
typeset target_env="$env_home$new_env"
436437

437438
if [ ! -e "$source_env" ]
438439
then
@@ -442,12 +443,12 @@ cpvirtualenv() {
442443

443444
cp -r "$source_env" "$target_env"
444445
for script in $( ls $target_env/bin/* )
445-
do
446+
do
446447
newscript="$script-new"
447448
sed "s|$source_env|$target_env|g" < "$script" > "$newscript"
448449
mv "$newscript" "$script"
449450
chmod a+x "$script"
450-
done
451+
done
451452

452453
virtualenv "$target_env" --relocatable
453454
sed "s/VIRTUAL_ENV\(.*\)$env_name/VIRTUAL_ENV\1$new_env/g" < "$source_env/bin/activate" > "$target_env/bin/activate"

0 commit comments

Comments
 (0)