generated from LoveDuckie/python-tool-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests.sh
executable file
·48 lines (38 loc) · 1.41 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
#!/usr/bin/env bash
<<EOF
Tool \ Shell Scripts \ Run \ Tests
Run the unit tests discovered in the codebase.
EOF
CURRENT_SCRIPT_DIRECTORY=${CURRENT_SCRIPT_DIRECTORY:-$(dirname $(realpath ${BASH_SOURCE[0]:-${(%):-%x}}))}
export SHARED_EXT_SCRIPTS_PATH=${SHARED_EXT_SCRIPTS_PATH:-$(realpath $CURRENT_SCRIPT_DIRECTORY)}
export CURRENT_SCRIPT_FILENAME=${CURRENT_SCRIPT_FILENAME:-$(basename ${BASH_SOURCE[0]:-${(%):-%x}})}
export CURRENT_SCRIPT_FILENAME_BASE=${CURRENT_SCRIPT_FILENAME%.*}
. "$SHARED_EXT_SCRIPTS_PATH/shared_functions.sh"
write_header
# Check if coverage is installed
if ! command -v coverage &> /dev/null
then
echo "Coverage is not installed. Please install it by running 'pip install coverage'."
exit 1
fi
# Check if the user provided a directory or file to test
if [ -z "$1" ]; then
write_info "run_tests" "Usage: $0 <test-directory-or-file>"
exit 1
fi
# Run the unit tests with coverage
poetry run coverage run --source=. -m unittest discover -s $1
# Check if the tests passed
if [ $? -eq 0 ]; then
write_info "run_tests" "Unit tests passed."
else
write_error "run_tests" "Some unit tests failed. Please review the errors."
exit 1
fi
# Generate coverage report
write_info "run_tests" "Generating coverage report..."
coverage report -m
coverage html
write_info "run_tests" "Coverage report generated. Open 'htmlcov/index.html' to view the detailed report."
write_success "run_tests" "Done"
exit 0