-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_tests.sh
executable file
·83 lines (75 loc) · 2.61 KB
/
run_tests.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
#!/bin/bash
# =============================================================================
# Python unit tests and code ratings
#
# Objective: Test all python test modules and rate all python scripts
#
# Version: 0.2.0
#
# Author: Diptesh
#
# Date: Jun 24, 2020
#
# =============================================================================
# Set test directory
path="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)\
/$(basename "${BASH_SOURCE[0]}")"
test_dir=$(sed -E 's/(.+)(\/bin\/.+)/\1\/tests/' <<< $path)
proj_dir=$(sed -E 's/(.+)(\/bin\/.+)/\1/' <<< $path)
if [[ -z $1 ]]
then
module="-a"
else
module=$1
fi
printf "=%.0s" {1..70}
# Run unit tests
if [[ $module == "-a" || $module == "-u" ]]
then
printf "\nRunning unit & integration tests ...\n\n"
coverage run -m unittest discover -v -s $test_dir -p "test_*.py"
printf "=%.0s" {1..70}
printf "\n"
printf "\nComputing test coverage ...\n\n"
coverage report -m --omit="*/tests/test_*,*/opt/spark-*" 2>&1 | tee "$proj_dir/logs/cov.out"
COV_SCORE=`grep "TOTAL" $proj_dir/logs/cov.out | tail -1 | awk '{ printf("%d", $4) }'`
COV_COLOR="red"
if [[ $COV_SCORE == "100" ]]
then
COV_COLOR="dagreen"
fi
sed -i "4s/.*/\[\!\[Coverage score\]\(\https\:\/\/img\.shields\.io\/badge\/coverage\-$COV_SCORE\%25\-$COV_COLOR.svg\)\]\(\.\/logs\/cov\.out\)/" "$proj_dir/README.md"
printf "=%.0s" {1..70}
fi
# Rate coding styles for all python scripts
if [[ $module == "-a" || $module == "-r" ]]
then
printf "\nRating code style ...\n\n"
score=0
cnt=0
rm $proj_dir/logs/pylint/*.out
for i in $(find "$proj_dir" -name "*.py")
do
file=${i#$(dirname "$(dirname "$i")")/}
printf "%-67s %s" "$file"
file_dir=$(sed -E 's/(.+\/)(.+\.py)/\1/' <<< $i)
cd "$file_dir"
pylint "$i" > "$proj_dir/logs/pylint/pylint.out"
PYLINT_SCORE=`grep "Your code has been rated" $proj_dir/logs/pylint/pylint.out | cut -d" " -f7 | cut -d"." -f1`
file_name=$(sed -E 's/(\/)/-/' <<< $file)
file_name=$(sed -E 's/(\.)/-/' <<< $file_name)
cp "$proj_dir/logs/pylint/pylint.out" "$proj_dir/logs/pylint/$file_name.out"
score=$((score + PYLINT_SCORE))
cnt=$((cnt + 1))
printf "$PYLINT_SCORE\n"
cd "$proj_dir"
done
tot_score=$(echo "scale=1; $score/$cnt" | bc)
printf "\nTotal score: $tot_score\n"
# Add pylint badge to README.md
sed -i "3s/.*/\[\!\[pylint Score\]\(https\:\/\/mperlet\.github\.io\/pybadge\/badges\/$tot_score.svg\)\]\(\.\/logs\/pylint\/\)/" "$proj_dir/README.md"
printf "=%.0s" {1..70}
printf "\n"
fi
pipreqs --force --use-local $proj_dir &> $proj_dir/logs/pip.out
exit 0