Skip to content

Commit 6473099

Browse files
committed
test cleanup and enhancement
1 parent 19b3de7 commit 6473099

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

tests/test_mkvirtualenv.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
#set -x
44

55
test_dir=$(dirname $0)
6-
source "$test_dir/../virtualenvwrapper.sh"
7-
86
export WORKON_HOME="${TMPDIR:-/tmp}/WORKON_HOME"
97

108
oneTimeSetUp() {
119
rm -rf "$WORKON_HOME"
1210
mkdir -p "$WORKON_HOME"
11+
source "$test_dir/../virtualenvwrapper.sh"
1312
}
1413

1514
oneTimeTearDown() {
@@ -39,12 +38,12 @@ test_activates () {
3938

4039
test_hooks () {
4140
export pre_test_dir=$(cd "$test_dir"; pwd)
42-
echo "echo GLOBAL premkvirtualenv >> \"$pre_test_dir/catch_output\"" >> "$WORKON_HOME/premkvirtualenv"
41+
echo "echo GLOBAL premkvirtualenv \`pwd\` \"\$@\" >> \"$pre_test_dir/catch_output\"" >> "$WORKON_HOME/premkvirtualenv"
4342
chmod +x "$WORKON_HOME/premkvirtualenv"
4443
echo "echo GLOBAL postmkvirtualenv >> $test_dir/catch_output" > "$WORKON_HOME/postmkvirtualenv"
4544
mkvirtualenv "env3"
4645
output=$(cat "$test_dir/catch_output")
47-
expected="GLOBAL premkvirtualenv
46+
expected="GLOBAL premkvirtualenv $WORKON_HOME env3
4847
GLOBAL postmkvirtualenv"
4948
assertSame "$expected" "$output"
5049
rm -f "$WORKON_HOME/premkvirtualenv"

tests/test_run_hook.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ test_virtualenvwrapper_source_hook_permissions() {
4242
}
4343

4444
test_virtualenvwrapper_run_hook_permissions() {
45+
echo "#!/bin/sh" > "$WORKON_HOME/prermvirtualenv"
4546
echo "echo run $@ >> \"$test_dir/catch_output\"" >> "$WORKON_HOME/prermvirtualenv"
4647
chmod -x "$WORKON_HOME/prermvirtualenv"
4748
touch "$test_dir/catch_output"
48-
virtualenvwrapper_run_hook "pre_rmvirtualenv" "foo"
49+
error=$(virtualenvwrapper_run_hook "pre_rmvirtualenv" "foo" 2>&1 | grep "ERROR")
4950
output=$(cat "$test_dir/catch_output")
5051
expected=""
5152
assertSame "$expected" "$output"
53+
assertSame "virtualenvwrapper.user_scripts ERROR: Could not run $WORKON_HOME/prermvirtualenv. [Errno 13] Permission denied" "$error"
5254
}
5355

5456
. "$test_dir/shunit2"

tests/test_workon.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
#set -x
44

55
test_dir=$(dirname $0)
6-
source "$test_dir/../virtualenvwrapper.sh"
76

87
export WORKON_HOME="${TMPDIR:-/tmp}/WORKON_HOME"
98

109
oneTimeSetUp() {
1110
rm -rf "$WORKON_HOME"
1211
mkdir -p "$WORKON_HOME"
12+
source "$test_dir/../virtualenvwrapper.sh"
1313
mkvirtualenv "env1"
1414
}
1515

@@ -70,8 +70,8 @@ test_deactivate_hooks () {
7070

7171
for t in pre post
7272
do
73-
echo "echo GLOBAL ${t}deactivate >> $test_dir/catch_output" > "$WORKON_HOME/${t}deactivate"
74-
echo "echo ENV ${t}deactivate >> $test_dir/catch_output" > "$WORKON_HOME/env1/bin/${t}deactivate"
73+
echo "echo GLOBAL ${t}deactivate \$VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV >> $test_dir/catch_output" > "$WORKON_HOME/${t}deactivate"
74+
echo "echo ENV ${t}deactivate \$VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV >> $test_dir/catch_output" > "$WORKON_HOME/env1/bin/${t}deactivate"
7575
done
7676

7777
touch "$test_dir/catch_output"
@@ -81,8 +81,8 @@ test_deactivate_hooks () {
8181
output=$(cat "$test_dir/catch_output")
8282
expected="ENV predeactivate
8383
GLOBAL predeactivate
84-
ENV postdeactivate
85-
GLOBAL postdeactivate"
84+
ENV postdeactivate $WORKON_HOME/env1
85+
GLOBAL postdeactivate $WORKON_HOME/env1"
8686
assertSame "$expected" "$output"
8787

8888
for t in pre post

0 commit comments

Comments
 (0)