Skip to content

Commit 66c02ef

Browse files
committed
fix #32 by removing use of 'with' ; add tests for python 2.6 and 2.5
1 parent b19a83c commit 66c02ef

File tree

10 files changed

+43
-15
lines changed

10 files changed

+43
-15
lines changed

Makefile

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

4+
# The main version of Python supported.
5+
PRIMARY_PYTHON_VERSION=2.6
6+
7+
# The test-quick pattern changes the definition of
8+
# this variable to only run against a single version of python.
9+
ifeq ($(SUPPORTED_PYTHON_VERSIONS),)
10+
SUPPORTED_PYTHON_VERSIONS=2.5 2.6
11+
endif
12+
413
# Default target is to show help
514
help:
615
@echo "sdist - Source distribution"
@@ -44,7 +53,7 @@ docs/sphinx/web/templates/base.html: ~/Devel/doughellmann/doughellmann/templates
4453
TEST_SCRIPTS=$(wildcard tests/test*.sh)
4554

4655
.PHONY: develop test test-bash test-sh test-zsh test-loop test-install
47-
test: develop test-bash test-sh test-zsh test-install
56+
test: test-bash test-sh test-zsh test-install
4857

4958
develop:
5059
python setup.py develop
@@ -58,13 +67,26 @@ test-sh:
5867
test-zsh:
5968
TEST_SHELL="zsh -o shwordsplit" $(MAKE) test-loop
6069

70+
# For each supported version of Python,
71+
# - Create a new virtualenv in a temporary directory.
72+
# - Install virtualenvwrapper into the new virtualenv
73+
# - Run each test script in tests
6174
test-loop:
62-
@for test_script in $(wildcard tests/test*.sh) ; do \
63-
echo '********************************************************************************' ; \
64-
echo "Running $$test_script with $(TEST_SHELL)" ; \
65-
SHUNIT_PARENT=$$test_script $(TEST_SHELL) $$test_script || exit 1 ; \
66-
echo ; \
75+
for py_ver in $(SUPPORTED_PYTHON_VERSIONS) ; do \
76+
(cd $$TMPDIR/ && rm -rf virtualenvwrapper-test-env \
77+
&& virtualenv -p /Library/Frameworks/Python.framework/Versions/$$py_ver/bin/python$$py_ver --no-site-packages virtualenvwrapper-test-env) \
78+
|| exit 1 ; \
79+
$$TMPDIR/virtualenvwrapper-test-env/bin/python setup.py install || exit 1 ; \
80+
for test_script in $(wildcard tests/test*.sh) ; do \
81+
echo '********************************************************************************' ; \
82+
echo "Running $$test_script with $(TEST_SHELL) under Python $$py_ver" ; \
83+
VIRTUALENVWRAPPER_PYTHON=$$TMPDIR/virtualenvwrapper-test-env/bin/python SHUNIT_PARENT=$$test_script $(TEST_SHELL) $$test_script || exit 1 ; \
84+
echo ; \
85+
done \
6786
done
6887

88+
test-quick:
89+
SUPPORTED_PYTHON_VERSIONS=$(PRIMARY_PYTHON_VERSION) $(MAKE) test-bash
90+
6991
test-install:
7092
bash ./tests/manual_test_install.sh `pwd`/dist "$(VERSION)"

tests/test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
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"
13+
echo $PYTHONPATH
1314
}
1415

1516
oneTimeTearDown() {

tests/test_add2virtualenv.sh

Lines changed: 1 addition & 1 deletion
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
}
1414

1515
oneTimeTearDown() {

tests/test_cd.sh

Lines changed: 1 addition & 1 deletion
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
}
1414

1515
oneTimeTearDown() {

tests/test_cp.sh

Lines changed: 1 addition & 1 deletion
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
setUp () {
1110
rm -rf "$WORKON_HOME"
1211
mkdir -p "$WORKON_HOME"
12+
source "$test_dir/../virtualenvwrapper.sh"
1313
echo
1414
rm -f "$test_dir/catch_output"
1515
}

tests/test_ls.sh

Lines changed: 1 addition & 1 deletion
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
}
1414

1515
oneTimeTearDown() {

tests/test_rmvirtualenv.sh

Lines changed: 1 addition & 1 deletion
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
}
1414

1515
oneTimeTearDown() {

tests/test_tmpdir.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#set -x
44

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

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

virtualenvwrapper.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ then
5252
fi
5353

5454
# Locate the global Python where virtualenvwrapper is installed.
55-
VIRTUALENVWRAPPER_PYTHON="$(which python)"
55+
if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ]
56+
then
57+
VIRTUALENVWRAPPER_PYTHON="$(which python)"
58+
fi
5659

5760
# Normalize the directory name in case it includes
5861
# relative path components.

virtualenvwrapper/user_scripts.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,14 @@ def make_hook(filename, comment):
100100
filename = os.path.expanduser(os.path.expandvars(filename))
101101
if not os.path.exists(filename):
102102
log.info('Creating %s', filename)
103-
with open(filename, 'wt') as f:
103+
f = open(filename, 'wt')
104+
try:
104105
f.write("""#!%(shell)s
105106
# %(comment)s
106107
107108
""" % {'comment':comment, 'shell':os.environ.get('SHELL', '/bin/sh')})
109+
finally:
110+
f.close()
108111
os.chmod(filename, PERMISSIONS)
109112
return
110113

0 commit comments

Comments
 (0)