#!/usr/bin/env bash set -o errexit set -o nounset function run_python_tests() { GIT_ROOT=$(git rev-parse --show-toplevel) pushd "$GIT_ROOT" >/dev/null # If there's a `scripts` folder with a test script, run that if find "scripts" -name 'run_*_tests.sh' >/dev/null; then print_info "-> bash scripts/run_*_tests.sh" bash scripts/run_*_tests.sh return 0 fi popd >/dev/null REPO_NAME="$(basename $(pwd))" # Run ruff to do Python formatting print_info "-> ruff format" ruff format . echo "" print_info "-> ruff check --fix" ruff check --fix . echo "" # This is one repo which is a bit special -- I'm gradually trying to chase # the code into `src`, but for now I have to remember to look at *.py if [[ "$REPO_NAME" = "library-lookup" ]] then print_info '-> mypy *.py src tests' mypy *.py src tests else print_info '-> mypy src tests' if mypy src tests >/dev/null then mypy src tests --no-color-output else mypy src tests fi fi echo "" # Run the tests. print_info "-> coverage run -m pytest tests" coverage run -m pytest tests --quiet echo "" print_info "-> coverage report" if [[ $(coverage report --format=total) = "100" ]] then echo "100% coverage!" else coverage report fi } function run_rust_tests() { print_info "-> cargo fmt" cargo fmt echo "" print_info "-> cargo build" cargo build echo "" print_info -n "-> cargo test" cargo test --quiet } if test -f Cargo.toml then run_rust_tests else run_python_tests "$@" fi