-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·79 lines (66 loc) · 1.89 KB
/
test.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
#!/bin/bash
which pytest > /dev/null || { echo "Pytest not found, can't run tests."; exit 1; }
# coverage report settings
cov_report=html
required_coverage=95
open_report=false
generate_report=false
report=""
save_report=false
exit_first=""
while getopts "r:c:hogsx" opt; do
case $opt in
h)
echo "Usage: [-ogs] test.sh [-r <required coverage>] [-c <coverage report type>]"
echo "-o opens the coverage report in a browser after running tests. Requires -g"
echo "-g generates a coverage report"
echo "-s saves test coverage report to 'pytest-coverage.txt and pytest.xml"
echo "-x exits on first failure"
exit 0
;;
r)
required_coverage=$OPTARG
;;
c)
cov_report=$OPTARG
;;
g)
generate_report=true
;;
o)
open_report=true
;;
s)
save_report=true
;;
x)
exit_first="-x"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
if [ "$open_report" = true ] && [ "$generate_report" = false ] ; then
echo "Can't open report without generating it. Use -g to generate a report."
exit 1
fi
if [ "$generate_report" = true ] && [ "$save_report" = false ]; then
report="--cov=src/jpfreq --cov-branch --cov-report=$cov_report --cov-fail-under=$required_coverage"
elif [ "$generate_report" = true ] && [ "$save_report" = true ]; then
report="--cov=src/jpfreq --cov-branch --cov-fail-under=$required_coverage --junitxml=pytest.xml --cov-report=term-missing --cov-fail-under=$required_coverage"
fi
exit_code=0
# runs coverage with a html report
# fails if cov < required_coverage
result=$(pytest -n auto "$exit_first" $report tests/)
exit_code=$?
if [ "$save_report" = true ] ; then
echo "$result" > pytest-coverage.txt
fi
echo "$result"
ruff src/jpfreq/*.py || exit_code=$?
if [ "$open_report" = true ] ; then
open htmlcov/index.html
fi
exit $exit_code