Skip to content

Commit 63fac44

Browse files
committed
Allow tests to run in parallel
Update the test implementations so the different test environments can be run in parallel under detox. Change-Id: Ia4a017e32d231b066dd1ae6027c6644bb4e1d611
1 parent 8d0e1e6 commit 63fac44

34 files changed

+69
-97
lines changed

tests/run_tests

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- mode: shell-script -*-
12
#set -x
23

34
envdir="$1"
@@ -59,6 +60,7 @@ do
5960
echo " KSH_VERSION=$KSH_VERSION"
6061
echo " virtualenv=$(which virtualenv)"
6162
echo " ZSH=$ZSH_NAME $ZSH_EVAL_CONTEXT"
63+
echo " TMPDIR=$TMPDIR"
6264
echo
6365
SHUNIT_PARENT="$test_script"
6466
export SHUNIT_PARENT

tests/setup.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
#set -x
44

5-
tmplocation=${TMPDIR:-/tmp}
5+
# tmplocation=${TMPDIR:-/tmp}
6+
# export WORKON_HOME="$(echo ${tmplocation}/WORKON_HOME.$$ | sed 's|//|/|g')"
7+
# export PROJECT_HOME="$(echo ${tmplocation}/PROJECT_HOME.$$ | sed 's|//|/|g')"
68

7-
export WORKON_HOME="$(echo ${tmplocation}/WORKON_HOME.$$ | sed 's|//|/|g')"
8-
export PROJECT_HOME="$(echo ${tmplocation}/PROJECT_HOME.$$ | sed 's|//|/|g')"
9+
export WORKON_HOME=$(mktemp -d -t "WORKON_HOME.$$")
10+
export PROJECT_HOME=$(mktemp -d -t "PROJECT_HOME.$$")
911

1012
#unset HOOK_VERBOSE_OPTION

tests/test.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ oneTimeTearDown() {
1515

1616
setUp () {
1717
echo
18-
rm -f "$test_dir/catch_output"
1918
unset VIRTUALENVWRAPPER_INITIALIZED
19+
rm -f "$TMPDIR/catch_output"
2020
}
2121

2222
test_virtualenvwrapper_initialize() {
@@ -26,10 +26,9 @@ test_virtualenvwrapper_initialize() {
2626
assertTrue "Global $WORKON_HOME/$hook was not created" "[ -f $WORKON_HOME/$hook ]"
2727
assertTrue "Global $WORKON_HOME/$hook is not executable" "[ -x $WORKON_HOME/$hook ]"
2828
done
29-
export pre_test_dir=$(cd "$test_dir"; pwd)
30-
echo "echo GLOBAL initialize >> \"$pre_test_dir/catch_output\"" >> "$WORKON_HOME/initialize"
29+
echo "echo GLOBAL initialize >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/initialize"
3130
virtualenvwrapper_initialize
32-
output=$(cat "$test_dir/catch_output")
31+
output=$(cat "$TMPDIR/catch_output")
3332
expected="GLOBAL initialize"
3433
assertSame "$expected" "$output"
3534
}

tests/test_add2virtualenv.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ oneTimeTearDown() {
1515

1616
setUp () {
1717
echo
18-
rm -f "$test_dir/catch_output"
1918
}
2019

2120
test_add2virtualenv () {

tests/test_allvirtualenv.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ oneTimeTearDown() {
1919

2020
setUp () {
2121
echo
22-
rm -f "$test_dir/catch_output"
2322
}
2423

2524
tearDown () {

tests/test_cd.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ oneTimeTearDown() {
1818

1919
setUp () {
2020
echo
21-
rm -f "$test_dir/catch_output"
2221
workon cd-test
2322
}
2423

tests/test_cp.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ setUp () {
77
rm -rf "$WORKON_HOME"
88
mkdir -p "$WORKON_HOME"
99
source "$test_dir/../virtualenvwrapper.sh"
10-
rm -f "$test_dir/catch_output"
10+
rm -f "$TMPDIR/catch_output"
1111
echo
1212
}
1313

@@ -107,27 +107,25 @@ test_source_does_not_exist () {
107107
test_hooks () {
108108
mkvirtualenv "source" >/dev/null 2>&1
109109

110-
export pre_test_dir=$(cd "$test_dir"; pwd)
111-
112110
# Set the interpreter of the hook script to the simple shell
113111
echo "#!/bin/sh" > "$WORKON_HOME/premkvirtualenv"
114-
echo "echo GLOBAL premkvirtualenv \`pwd\` \"\$@\" >> \"$pre_test_dir/catch_output\"" >> "$WORKON_HOME/premkvirtualenv"
112+
echo "echo GLOBAL premkvirtualenv \`pwd\` \"\$@\" >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/premkvirtualenv"
115113
chmod +x "$WORKON_HOME/premkvirtualenv"
116114

117-
echo "echo GLOBAL postmkvirtualenv >> $test_dir/catch_output" > "$WORKON_HOME/postmkvirtualenv"
115+
echo "echo GLOBAL postmkvirtualenv >> $TMPDIR/catch_output" > "$WORKON_HOME/postmkvirtualenv"
118116

119117
# Set the interpreter of the hook script to the simple shell
120118
echo "#!/bin/sh" > "$WORKON_HOME/precpvirtualenv"
121-
echo "echo GLOBAL precpvirtualenv \`pwd\` \"\$@\" >> \"$pre_test_dir/catch_output\"" >> "$WORKON_HOME/precpvirtualenv"
119+
echo "echo GLOBAL precpvirtualenv \`pwd\` \"\$@\" >> \"$TMPDIR/catch_output\"" >> "$WORKON_HOME/precpvirtualenv"
122120
chmod +x "$WORKON_HOME/precpvirtualenv"
123121

124122
# Set the interpreter of the hook script to the simple shell
125123
echo "#!/bin/sh" > "$WORKON_HOME/postcpvirtualenv"
126-
echo "echo GLOBAL postcpvirtualenv >> $test_dir/catch_output" > "$WORKON_HOME/postcpvirtualenv"
124+
echo "echo GLOBAL postcpvirtualenv >> $TMPDIR/catch_output" > "$WORKON_HOME/postcpvirtualenv"
127125

128126
cpvirtualenv "source" "destination" >/dev/null 2>&1
129127

130-
output=$(cat "$test_dir/catch_output")
128+
output=$(cat "$TMPDIR/catch_output")
131129
workon_home_as_pwd=$(cd $WORKON_HOME; pwd)
132130

133131
expected="GLOBAL precpvirtualenv $workon_home_as_pwd $workon_home_as_pwd/source destination

tests/test_cpvirtualenv.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ setUp () {
77
rm -rf "$WORKON_HOME"
88
mkdir -p "$WORKON_HOME"
99
source "$test_dir/../virtualenvwrapper.sh"
10-
rm -f "$test_dir/catch_output"
1110
echo
1211
}
1312

@@ -202,7 +201,7 @@ test_clone_venv_using_vars () {
202201
assertTrue "Cloned virtualenv already exists" "[ ! -d $WORKON_HOME/cpvenv_test ]"
203202

204203
$VIRTUALENVWRAPPER_VIRTUALENV "$TMPDIR/cpvenv_test" >/dev/null 2>&1
205-
touch "$tmplocation/cpvenv_test/mytestpackage"
204+
touch "$TMPDIR/cpvenv_test/mytestpackage"
206205

207206
assertTrue "Virtualenv to clone didn't get created" "[ -d $TMPDIR/cpvenv_test ]"
208207
assertTrue "Cloned virtualenv already exists" "[ ! -d $WORKON_HOME/cpvenv_test ]"

tests/test_deactivate.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ oneTimeTearDown() {
1616

1717
setUp () {
1818
echo
19-
rm -f "$test_dir/catch_output"
19+
rm -f "$TMPDIR/catch_output"
2020
}
2121

2222
test_deactivate () {
@@ -32,15 +32,15 @@ test_deactivate_hooks () {
3232

3333
for t in pre post
3434
do
35-
echo "echo GLOBAL ${t}deactivate \$VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV >> $test_dir/catch_output" > "$WORKON_HOME/${t}deactivate"
36-
echo "echo ENV ${t}deactivate \$VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV >> $test_dir/catch_output" > "$WORKON_HOME/env1/bin/${t}deactivate"
35+
echo "echo GLOBAL ${t}deactivate \$VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV >> $TMPDIR/catch_output" > "$WORKON_HOME/${t}deactivate"
36+
echo "echo ENV ${t}deactivate \$VIRTUALENVWRAPPER_LAST_VIRTUAL_ENV >> $TMPDIR/catch_output" > "$WORKON_HOME/env1/bin/${t}deactivate"
3737
done
3838

39-
touch "$test_dir/catch_output"
39+
touch "$TMPDIR/catch_output"
4040

4141
deactivate
4242

43-
output=$(cat "$test_dir/catch_output")
43+
output=$(cat "$TMPDIR/catch_output")
4444
expected="ENV predeactivate
4545
GLOBAL predeactivate
4646
ENV postdeactivate $WORKON_HOME/env1

tests/test_derive_workon_home.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ oneTimeTearDown() {
1717

1818
setUp () {
1919
echo
20-
rm -f "$test_dir/catch_output"
2120
WORKON_HOME="$TMP_WORKON_HOME"
2221
}
2322

0 commit comments

Comments
 (0)