-
Notifications
You must be signed in to change notification settings - Fork 27
/
runtests.sh
executable file
·151 lines (123 loc) · 3.54 KB
/
runtests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env bash
# Run tests with all supported Django and Python versions.
# If --install is passed, also test installation from PyPI.
set -e
# Get the dir where the script is located.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [[ $1 == '--install' || $2 == '--install' ]] ; then
test_install=true
else
test_install=false
fi
if [[ $1 == '--upgrade' || $2 == '--upgrade' ]] ; then
upgrade=true
else
upgrade=false
fi
function activate {
v=$1
pv=$2
install=$3
cdir=`pwd`
# Setup virtual environment for the specified Django version if absent.
IFS='.' read v1 v2 <<< "$v"
if $install ; then
env="$cdir/envs/install-$pv-$v"
else
env="$cdir/envs/$pv-$v"
fi
if [ ! -d $env ] ; then
virtualenv --no-site-packages -p python$pv $env
fi
source $env/bin/activate
# Install or upgrade the required Django version.
if $upgrade ; then
packages="django>=$v1.$v2,<$v1.$(($v2+1))"
if [[ $pv == "2" ]] ; then
packages="$packages pysqlite"
fi
pip install -U --cache-dir=$cdir/envs/cache $packages
fi
}
function test {
v=$1
pv=$2
cdir=`pwd`
echo ""
echo "Testing with Django $v and Python $pv"
echo "===================================================================="
activate $v $pv false
# Run tests in a standalone environment.
$env/bin/python$pv $DIR/mail_templated/test_utils/run.py
deactivate
# Test installation into virtual environment.
if $test_install ; then
activate $v $pv true
# Install a fresh version of the application.
find $DIR \( -name "*.pyc" -o -name __pycache__ \) -delete
pip install -U --force-reinstall "$DIR/dist/django-mail-templated-test.tar.gz"
# Create test Django project.
project_dir="$cdir/testproject"
if [ -d $project_dir ] ; then
rm -r $project_dir
fi
mkdir $project_dir
$env/bin/django-admin.py startproject testproject $project_dir
cat $DIR/mail_templated/test_utils/settings_extra.py >> $project_dir/testproject/settings.py
# Run tests via the test project.
$project_dir/manage.py test mail_templated
# Cleanup.
rm -r $project_dir
deactivate
fi
echo ""
}
current_dir=`pwd`
cd $DIR
# Make new package for tests.
if $install ; then
find $DIR -name __pycache__ -exec rm -r {} \; || true
find $DIR -name "*.pyc" -exec rm {} \;
MAIL_TEMPLATED_VERSION=test python $DIR/setup.py sdist
fi
cd $DIR/..
p2v=`pyenv versions --bare | grep -P '^2.\d+.\d+$' | tail -n 1`
p34v=`pyenv versions --bare | grep -P '^3.4.\d+$' | tail -n 1`
p3v=`pyenv versions --bare | grep -P '^3.\d+.\d+$' | tail -n 1`
export PYENV_VERSION="$p2v:$p3v:$p34v"
echo ""
echo "Python versions to be used: $p2v, $p34v, $p3v"
echo "===================================================================="
p2v=`echo $p2v | sed -r 's/\.[^.]+$//'`
p34v=`echo $p34v | sed -r 's/\.[^.]+$//'`
p3v=`echo $p3v | sed -r 's/\.[^.]+$//'`
function run_thread_0 {
test "1.4" $p2v
test "1.5" $p2v
test "1.5" $p34v
}
function run_thread_1 {
test "1.6" $p2v
test "1.6" $p34v
test "1.7" $p2v
test "1.7" $p34v
}
function run_thread_2 {
test "1.8" $p2v
test "1.8" $p34v
test "1.9" $p2v
test "1.9" $p3v
}
function run_thread_3 {
test "1.10" $p2v
test "1.10" $p3v
}
if [ $CIRCLE_NODE_INDEX ] ; then
run_thread_$CIRCLE_NODE_INDEX
else
run_thread_0
run_thread_1
run_thread_2
run_thread_3
fi
cd $current_dir