Skip to content

Commit 25ab840

Browse files
committed
convert test scripts to use tox instead of home-grown multi-version system in the Makefile
1 parent cdb750b commit 25ab840

20 files changed

+129
-85
lines changed

.hgignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ tests/testpackage/testpackage.egg-info
1515
trace.txt
1616
virtualenvwrapper.egg-info
1717
virtualenvwrapper/docs
18+
.tox
1819

1920
syntax: re
2021
.DS_Store

ChangeLog

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
2010-12-24 Doug Hellmann <[email protected]>
2+
3+
* virtualenvwrapper.sh (cpvirtualenv): Ensure that both pre hooks
4+
are run, even if one produces an error.
5+
6+
* virtualenvwrapper/user_scripts.py: Change log message format.
7+
8+
* tox.ini: Configuration file for running tests under tox.
9+
10+
* tests/test_run_hook.sh (test_virtualenvwrapper_run_hook_permissions):
11+
Fix the expected output message.
12+
13+
* tests/*: Make sure all of the test scripts have execute permission.
14+
15+
* tests/test.sh (test_virtualenvwrapper_verify_workon_home_missing_dir_quiet_init):
16+
Use source instead of starting another shell, since zsh doesn't
17+
play nicely with inheriting environment settings otherwise.
18+
(test_python_interpreter_set_incorrectly): Force
19+
VIRTUALENVWRAPPER_PYTHON before running the script in a sub-shell.
20+
21+
* tests/run_tests: Script to run through all of the other test
22+
scripts one at a time.
23+
124
2010-09-18 Doug Hellmann <[email protected]>
225

326
* virtualenvwrapper.sh: Apply patch from Zach Voase to fix

Makefile

Lines changed: 4 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
11
# Get the version of the app. This is used in the doc build.
22
export VERSION=$(shell python setup.py --version)
33

4-
# Locations of Python interpreter binaries
5-
PYTHON27=/Users/dhellmann/Devel/virtualenvwrapper/Python/2.7b1/bin/python2.7
6-
ifeq ($VIRTUAL_ENV,)
7-
PYTHON26=$(shell which python2.6)
8-
else
9-
PYTHON26=/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
10-
endif
11-
PYTHON25=/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5
12-
PYTHON24=/Users/dhellmann/Devel/virtualenvwrapper/Python/2.4.6/bin/python2.4
13-
14-
# The test-quick pattern changes the definition of
15-
# this variable to only run against a single version of python.
16-
ifeq ($(PYTHON_BINARIES),)
17-
PYTHON_BINARIES=$(PYTHON26) $(PYTHON27) $(PYTHON25) $(PYTHON24)
18-
endif
19-
20-
SUPPORTED_SHELLS=bash sh ksh zsh
21-
224
# Default target is to show help
235
help:
246
@echo "sdist - Source distribution"
@@ -67,56 +49,11 @@ register:
6749
python setup.py register
6850

6951
# Testing
70-
TEST_SCRIPTS=$(wildcard tests/test*.sh)
71-
7252
test:
73-
for name in $(SUPPORTED_SHELLS) ; do \
74-
$(MAKE) test-$$name || exit 1 ; \
75-
done
76-
$(MAKE) test-install
53+
tox
54+
55+
test-quick:
56+
tox -e py27
7757

7858
develop:
7959
python setup.py develop
80-
81-
test-bash test-ksh test-sh:
82-
TEST_SHELL=$(subst test-,,$@) $(MAKE) test-loop
83-
84-
test-zsh:
85-
TEST_SHELL="zsh -o shwordsplit" $(MAKE) test-loop
86-
87-
# For each supported version of Python,
88-
# - Create a new virtualenv in a temporary directory.
89-
# - Install virtualenvwrapper into the new virtualenv
90-
# - Run each test script in tests
91-
test-loop:
92-
for py_bin in $(PYTHON_BINARIES) ; do \
93-
(cd $$TMPDIR/ && rm -rf virtualenvwrapper-test-env \
94-
&& virtualenv -p $$py_bin --no-site-packages virtualenvwrapper-test-env) \
95-
|| exit 1 ; \
96-
$$TMPDIR/virtualenvwrapper-test-env/bin/python setup.py install || exit 1 ; \
97-
for test_script in tests/test*.sh ; do \
98-
echo ; \
99-
echo '********************************************************************************' ; \
100-
echo "Running $$test_script with $(TEST_SHELL) under Python $(basename $$py_bin)" ; \
101-
echo ; \
102-
HOOK_VERBOSE_OPTION=-v VIRTUALENVWRAPPER_PYTHON=$$TMPDIR/virtualenvwrapper-test-env/bin/python SHUNIT_PARENT=$$test_script $(TEST_SHELL) $$test_script || exit 1 ; \
103-
echo ; \
104-
done \
105-
done
106-
107-
test-quick:: test-26
108-
109-
test-24:
110-
PYTHON_BINARIES=$(PYTHON24) $(MAKE) test-bash
111-
112-
test-25:
113-
PYTHON_BINARIES=$(PYTHON25) $(MAKE) test-bash
114-
115-
test-26:
116-
PYTHON_BINARIES=$(PYTHON26) $(MAKE) test-bash
117-
118-
test-27:
119-
PYTHON_BINARIES=$(PYTHON27) $(MAKE) test-bash
120-
121-
test-install:
122-
bash ./tests/manual_test_install.sh `pwd`/dist "$(VERSION)"

docs/en/developers.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ Running Tests
6565
=============
6666

6767
The test suite for virtualenvwrapper uses `shunit2
68-
<http://shunit2.googlecode.com/>`_. To run the tests under bash, sh,
69-
and zsh, use ``make test``. In order to add new tests, you will need
70-
to modify or create an appropriate script in the ``tests`` directory.
68+
<http://shunit2.googlecode.com/>`_ and `tox
69+
<http://codespeak.net/tox>`_. To run the tests under bash, sh, and
70+
zsh, use ``make test`` or just ``tox``. In order to add new tests,
71+
you will need to modify or create an appropriate script in the
72+
``tests`` directory.

tests/run_tests

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/sh
2+
3+
##
4+
## ONLY RUN THIS VIA TOX
5+
##
6+
7+
#set -x
8+
9+
envdir="$1"
10+
shift
11+
scripts="$*"
12+
if [ -z "$scripts" ]
13+
then
14+
scripts=$(ls tests/test*.sh)
15+
fi
16+
17+
# Force the tox virtualenv to be active.
18+
#
19+
# Since this script runs from within a separate shell created by tox,
20+
# the name of the virtualenv (in $VIRTUAL_ENV) is inherited, but the
21+
# shell functions and other settings created by the activate script
22+
# are *not* inherited.
23+
#
24+
source "$envdir/bin/activate"
25+
26+
# Set up virtualenvwrapper.hook_loader to print more details than usual for debugging.
27+
export HOOK_VERBOSE_OPTION=-vvv
28+
29+
# Force virtualenvwrapper to use the python interpreter in the
30+
# tox-created virtualenv.
31+
export VIRTUALENVWRAPPER_PYTHON="$envdir/bin/python"
32+
33+
if [ -n "${ZSH_VERSION:-}" ]
34+
then
35+
export SHELL=$(which zsh)
36+
fi
37+
38+
# Run the test scripts with a little formatting around them to make it
39+
# easier to find where each script output starts.
40+
for test_script in $scripts
41+
do
42+
echo
43+
echo '********************************************************************************'
44+
echo "Running $test_script"
45+
echo " VIRTUAL_ENV=$VIRTUAL_ENV"
46+
echo " VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON"
47+
echo " $($VIRTUALENVWRAPPER_PYTHON -V 2>&1)"
48+
echo " PYTHONPATH=$PYTHONPATH"
49+
echo " SHELL=$SHELL"
50+
echo
51+
export SHUNIT_PARENT="$test_script"
52+
$test_script || exit 1
53+
echo
54+
done
55+
56+
exit 0

tests/test.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ oneTimeSetUp() {
1010
rm -rf "$WORKON_HOME"
1111
mkdir -p "$WORKON_HOME"
1212
source "$test_dir/../virtualenvwrapper.sh"
13-
echo $PYTHONPATH
1413
}
1514

1615
oneTimeTearDown() {
@@ -63,7 +62,7 @@ test_virtualenvwrapper_verify_workon_home_missing_dir_grep_options() {
6362
test_virtualenvwrapper_verify_workon_home_missing_dir_quiet_init() {
6463
old_home="$WORKON_HOME"
6564
export WORKON_HOME="$WORKON_HOME/not_there"
66-
output=`$SHELL $test_dir/../virtualenvwrapper.sh 2>&1`
65+
output=$(source $test_dir/../virtualenvwrapper.sh 2>&1)
6766
assertSame "" "$output"
6867
WORKON_HOME="$old_home"
6968
}
@@ -79,7 +78,7 @@ test_python_interpreter_set_incorrectly() {
7978
cd "$WORKON_HOME"
8079
mkvirtualenv --no-site-packages no_wrappers
8180
expected="ImportError: No module named virtualenvwrapper.hook_loader"
82-
output=$(VIRTUALENVWRAPPER_PYTHON=$VIRTUAL_ENV/bin/python $SHELL $return_to/virtualenvwrapper.sh 2>&1)
81+
output=$(VIRTUALENVWRAPPER_PYTHON=$(which python) $SHELL $return_to/virtualenvwrapper.sh 2>&1)
8382
echo "$output" | grep "$expected" 2>&1
8483
found=$?
8584
assertTrue "Expected \"$expected\", got: \"$output\"" "[ $found -eq 0 ]"

tests/test_add2virtualenv.sh

100644100755
File mode changed.

tests/test_cd.sh

100644100755
File mode changed.

tests/test_cp.sh

100644100755
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,20 @@ test_hooks () {
6363
mkvirtualenv "source"
6464

6565
export pre_test_dir=$(cd "$test_dir"; pwd)
66+
67+
# Set the interpreter of the hook script to the simple shell
68+
echo "#!/bin/sh" > "$WORKON_HOME/premkvirtualenv"
6669
echo "echo GLOBAL premkvirtualenv \`pwd\` \"\$@\" >> \"$pre_test_dir/catch_output\"" >> "$WORKON_HOME/premkvirtualenv"
6770
chmod +x "$WORKON_HOME/premkvirtualenv"
71+
6872
echo "echo GLOBAL postmkvirtualenv >> $test_dir/catch_output" > "$WORKON_HOME/postmkvirtualenv"
73+
74+
# Set the interpreter of the hook script to the simple shell
6975
echo "#!/bin/sh" > "$WORKON_HOME/precpvirtualenv"
7076
echo "echo GLOBAL precpvirtualenv \`pwd\` \"\$@\" >> \"$pre_test_dir/catch_output\"" >> "$WORKON_HOME/precpvirtualenv"
7177
chmod +x "$WORKON_HOME/precpvirtualenv"
78+
79+
# Set the interpreter of the hook script to the simple shell
7280
echo "#!/bin/sh" > "$WORKON_HOME/postcpvirtualenv"
7381
echo "echo GLOBAL postcpvirtualenv >> $test_dir/catch_output" > "$WORKON_HOME/postcpvirtualenv"
7482

@@ -83,6 +91,7 @@ GLOBAL postmkvirtualenv
8391
GLOBAL postcpvirtualenv"
8492

8593
assertSame "$expected" "$output"
94+
8695
rm -f "$WORKON_HOME/premkvirtualenv"
8796
rm -f "$WORKON_HOME/postmkvirtualenv"
8897
}

tests/test_deactivate.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)