forked from artemrizhov/django-mail-templated
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntests.sh
executable file
·110 lines (87 loc) · 2.76 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
#!/usr/bin/env bash
# Run tests with all supported Django and Python versions.
# If --install is passed, also test installation from PyPI.
set -e
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 /usr/bin/python$pv $env
fi
source $env/bin/activate
# Install or upgrade the required Django version.
if $upgrade ; then
pip install -U --download-cache=$cdir/envs/cache "django>=$v1.$v2,<$v1.$(($v2+1))"
fi
}
function test {
v=$1
pv=$2
cdir=`pwd`
echo "===================================================================="
echo "Testing with Django $v and Python $pv"
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 application.
find $DIR -name __pycache__ -exec rm -r {} \; || true
find $DIR -name "*.pyc" -exec rm {} \;
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
sed -i -- "s/\(INSTALLED_APPS\s*=\s*[\[(]\)/\1'mail_templated',/" $project_dir/testproject/settings.py
sed -i -- "s/\('django.db.backends.\)'/\1sqlite3'/" $project_dir/testproject/settings.py
sed -i -- "s/\('NAME': '\)'/\1db.sqlite3'/" $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/..
for v in "1.4" "1.5" "1.6" "1.7" "1.8" "1.9" ; do
test $v 2
if [[ ! ( $v =~ ^(1.4)$ ) ]] ; then
test $v 3
fi
done
cd $current_dir