-
Notifications
You must be signed in to change notification settings - Fork 5
/
runtest.sh
executable file
·89 lines (71 loc) · 2.71 KB
/
runtest.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
#!/bin/bash
# fail if smth fails
# the whole env will be running if test suite fails so you can debug
set -e
# for debugging this script, b/c I sometimes get
# unable to prepare context: The Dockerfile (Dockerfile.tests) must be within the build context (.)
set -x
# test coverage threshold
COVERAGE_THRESHOLD=90
export TERM=xterm
TERM=${TERM:-xterm}
# set up terminal colors
NORMAL=$(tput sgr0)
RED=$(tput bold && tput setaf 1)
GREEN=$(tput bold && tput setaf 2)
YELLOW=$(tput bold && tput setaf 3)
printf "%sCreate Virtualenv for Python deps ..." "${NORMAL}"
check_python_version() {
python3 tools/check_python_version.py 3 6
}
function prepare_venv() {
set +e
VIRTUALENV="$(which virtualenv)"
if [ $? -eq 1 ]; then
echo "Trying to find virualenv-3"
# python36 which is in CentOS does not have virtualenv binary
VIRTUALENV="$(which virtualenv-3)"
fi
if [ $? -eq 1 ]; then
echo "Virtualenv binary can't be found, using venv module instead"
# still don't have virtual environment -> use python3 directly
python3 -m venv venv_test && source venv_test/bin/activate
else
${VIRTUALENV} -p python3 venv_test && source venv_test/bin/activate
fi
if [ $? -ne 0 ]
then
printf "%sPython virtual environment can't be initialized%s" "${RED}" "${NORMAL}"
exit 1
fi
printf "%sPython virtual environment initialized%s\n" "${YELLOW}" "${NORMAL}"
set -e
}
check_python_version
[ "$NOVENV" == "1" ] || prepare_venv || exit 1
here=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
export PYTHONPATH=${here}/
# Need to use 19.2.3 version only as some of packages are deprecated in latest PIP version.
pip3 install pip==19.2.3
pip3 install -r requirements.txt
pip3 install -r requirements_test.txt
echo "*****************************************"
echo "*** Cyclomatic complexity measurement ***"
echo "*****************************************"
radon cc -s -a -e "venv/*,venv_test/*" .
echo "*****************************************"
echo "*** Maintainability Index measurement ***"
echo "*****************************************"
radon mi -s -e "venv/*,venv_test/*" .
echo "*****************************************"
echo "*** Unit tests ***"
echo "*****************************************"
echo "Starting test suite"
rm -rf "${here}/venv_test/maven"
mkdir "${here}/venv_test/maven"
rm -rf "${here}/venv_test/npm"
mkdir "${here}/venv_test/npm"
rm -rf "${here}/venv_test/pypi"
mkdir "${here}/venv_test/pypi"
DISABLE_AUTHENTICATION=1 PYTHONDONTWRITEBYTECODE=1 LOCAL_WORKING_DIRECTORY="${here}/venv_test" python "$(which pytest)" --cov=src/ --cov-report=xml --cov-fail-under=$COVERAGE_THRESHOLD -vv tests/
printf "%stests passed%s\n\n" "${GREEN}" "${NORMAL}"