-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·47 lines (41 loc) · 1.02 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
#!/bin/bash
cd tests
if [[ "$1" ]]; then
if [[ "$1" =~ ^[0-9]+$ ]]; then
filename=$(ls test_*.py | head -n $1 | tail -n 1)
echo "Running test: $filename"
else
if [[ "$1" =~ ^test_.*\.py$ ]]; then
filename=$1
else
echo "Invalid argument: $1"
echo "Usage: $0 [test_number|test_filename]"
ls test_*.py | nl -s ') '
exit 1
fi
fi
fi
if command -v coverage >/dev/null; then
echo "Running tests with coverage"
if [[ "$filename" ]]; then
coverage run -m unittest $filename
else
coverage run -m unittest discover -s $(dirname $0)
fi
coverage report -m
if [[ $(coverage report -m | tail -n 1 | awk '{print $4}' | tr -d '%') -lt 90 ]]; then
if [[ -z "$filename" ]]; then
echo "Coverage is less than 95%. Aborting..."
cd ..
exit 1
fi
fi
else
echo "Running tests without coverage"
python -m unittest discover -s $(dirname $0)
if [[ -z "$filename" ]]; then
echo "Coverage is not installed. Aborting..."
cd ..
exit 1
fi
fi