forked from bybatkhuu/module-python-logging
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·104 lines (84 loc) · 1.99 KB
/
test.sh
File metadata and controls
executable file
·104 lines (84 loc) · 1.99 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash
set -euo pipefail
## --- Base --- ##
_SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]:-"$0"}")" >/dev/null 2>&1 && pwd -P)"
_PROJECT_DIR="$(cd "${_SCRIPT_DIR}/.." >/dev/null 2>&1 && pwd)"
cd "${_PROJECT_DIR}" || exit 2
if ! command -v python >/dev/null 2>&1; then
echo "[ERROR]: Not found 'python' command, please install it first!" >&2
exit 1
fi
if ! command -v pytest >/dev/null 2>&1; then
echo "[ERROR]: Not found 'pytest' command, please install it first!" >&2
exit 1
fi
## --- Base --- ##
## --- Variables --- ##
# Flags:
_IS_LOGGING=false
_IS_COVERAGE=false
_IS_VERBOSE=false
## --- Variables --- ##
## --- Menu arguments --- ##
_usage_help() {
cat <<EOF
USAGE: ${0} [options]
OPTIONS:
-l, --log Enable logging. Default: false
-c, --cov Enable coverage. Default: false
-v, --verbose Enable verbose output. Default: false
-h, --help Show this help message.
EXAMPLES:
${0} -l -c -v
${0} --log
EOF
}
while [ $# -gt 0 ]; do
case "${1}" in
-l | --log)
_IS_LOGGING=true
shift;;
-c | --cov)
_IS_COVERAGE=true
shift;;
-v | --verbose)
_IS_VERBOSE=true
shift;;
-h | --help)
_usage_help
exit 0;;
*)
echo "[ERROR]: Failed to parse argument -> ${1}!" >&2
_usage_help
exit 1;;
esac
done
## --- Menu arguments --- ##
if [ "${_IS_COVERAGE}" == true ]; then
if ! python -c "import pytest_cov" &> /dev/null; then
echo "[ERROR]: 'pytest-cov' python package is not installed!" >&2
exit 1
fi
fi
## --- Main --- ##
main()
{
local _logging_param=""
local _coverage_param=""
local _verbose_param=""
if [ "${_IS_LOGGING}" == true ]; then
_logging_param="-o log_cli=true"
fi
if [ "${_IS_COVERAGE}" == true ]; then
_coverage_param="--cov"
fi
if [ "${_IS_VERBOSE}" == true ]; then
_verbose_param="-svv"
fi
echo "[INFO]: Running test..."
# shellcheck disable=SC2086
python -m pytest -v ${_coverage_param} ${_logging_param} ${_verbose_param} || exit 2
echo "[OK]: Done."
}
main
## --- Main --- ##