#!/usr/bin/env bash1# This script runs pytest for the whole project.2# It also generates a coverage report when the "pytest-cov" plugin is3# installed, including a HTML report45# Note: to run the tests, sage must be in your path. If necessary do6# export PATH=$PATH:/path/to/sage7# To run it, first install or upgrade "pytest", "pytest-cov" and8# "pyflakes". e.g. $ pip install --user -U pytest pytest-cov pyflakes9# or $ sage -pip install --user -U pytest pytest-cov pyflakes10# or inside the Sage environment: $ easy_install -U pytest11# $ easy_install -U pytest-cov12# $ easy_install -U pyflakes13# Second, call it in three ways, either14# $ ./test.sh to test all15# or16# $ ./test.sh coverage17# to test all and report test coverage18# or (for example)19# $ ./test.sh lmfdb/knowledge20# to test only a part of LMFDB21# To run tests with 3 cores in parallel, use22# $ ./test.sh -n 32324cd `dirname "$0"`2526# get rid of all cached .pyc files!27find . -name '*.pyc' -delete2829WHAT=''30COVER=''3132if [[ "$1" == "coverage" ]]; then33rm -rf lmfdb/htmlcov34shift35COVER='--cov=lmfdb --cov-report html'36fi3738WHAT="$@"3940SAGE_COMMAND=$SAGE41if [[ "$SAGE_COMMAND" == "" ]]; then42SAGE_COMMAND=sage43fi44echo "Using Sage command $SAGE_COMMAND"4546echo "Running pyflakes..."47read PYFLAKES_ERRCNT < <(find . | grep "\.py$" | xargs $SAGE_COMMAND -python -m pyflakes 2>&1 | tee /dev/stderr | grep "py:" -c)48if [[ $PYFLAKES_ERRCNT > 0 ]]; then49echo "WARNING: pyflakes reported $PYFLAKES_ERRCNT error(s)"50else51echo "pyflakes is happy"52fi5354ARGS='-v -s'5556if [[ -n $WHAT ]]; then57eval "$SAGE_COMMAND -python -m pytest $ARGS $COVER $WHAT"58else59eval "$SAGE_COMMAND -python -m pytest $ARGS $COVER lmfdb/"60fi6162if [[ $PYFLAKES_ERRCNT > 0 ]]; then63printf "\nWARNING: pyflakes reported $PYFLAKES_ERRCNT error(s)\n"64fi656667