Repository navigation
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·82 lines (76 loc) · 2.31 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·82 lines (76 loc) · 2.31 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
#!/usr/bin/env bash
# Example usage:
# Run specific test in interactive debug mode (will not proceed if linting/formatting errors):
# ./test.sh -t tests/test_fastq_validator_logic.py::TestFASTQValidatorLogic::test_fastq_groups_good -d
# Same as above, skipping linting/formatting:
# ./test.sh -n -t tests/test_fastq_validator_logic.py::TestFASTQValidatorLogic::test_fastq_groups_good -d
# Run all tests, skip linting/formatting, no interactive debugger:
# ./test.sh -n
# Run all tests, pass arbitrary argument directly to pytest:
# ./test.sh -- hello_pytest
usage() { echo "Usage: $0 [-n] [-t <test_string>]
-n : skip linting/formatting
-t : run specific test; use pytest format
example: tests/test_fastq_validator_logic.py::TestFASTQValidatorLogic::test_fastq_groups_bad
-d : pass --pdb to pytest for debugging
-- pass arbitrary other args following ' -- '" 1>&2; exit 1; }
# Define expected options
while getopts "nt:d" opt; do
case "$opt" in
n)
echo "Skipping linting/formatting"
SKIP="$1"
;;
t)
if [[ "$OPTARG" = "--" ]]; then
echo "-t must be followed by reference to a test"
usage
else
TEST="$OPTARG"
fi
;;
d)
DEBUG="--pdb"
;;
?)
usage
;;
esac
done
shift $((OPTIND - 1))
# Define -- as delimiter between options and arbitrary args to pass to pytest
[[ $1 = "--" ]] && shift
PARAMS=("$PARAMS$@")
# Run linting/formatting if not skipped with -n
# Respects configs in pyproject.toml / .flake8
# Note: black/isort will auto-format
if [ -z "$SKIP" ]; then
echo "Running linting/formatting checks..."
echo "--------"
echo "black"
black src
if [ $? -ne 0 ]; then
ERROR=1
fi
echo "--------"
echo "isort"
isort src
if [ $? -ne 0 ]; then
ERROR=1
fi
echo "--------"
echo "flake8"
flake8 src
if [ $? -ne 0 ]; then
ERROR=1
fi
fi
# Exit if linting/formatting errors found
if [[ $ERROR == 1 ]]; then
echo "Fix linting/formatting errors or pass -n/-no_lint to run tests."
exit 1
fi
# Run test suite with appropriate args
echo "--------"
echo "running python tests/pytest_runner.py $TEST $DEBUG ${PARAMS[@]}"
python tests/pytest_runner.py "$TEST" "$DEBUG" "${PARAMS[@]}" || exit 1