Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AndrewVSutherland
GitHub Repository: AndrewVSutherland/lmfdb
Path: blob/main/test.sh
1127 views
1
#!/usr/bin/env bash
2
# This script runs pytest for the whole project.
3
# It also generates a coverage report when the "pytest-cov" plugin is
4
# installed, including a HTML report
5
6
# Note: to run the tests, sage must be in your path. If necessary do
7
# export PATH=$PATH:/path/to/sage
8
# To run it, first install or upgrade "pytest", "pytest-cov" and
9
# "pyflakes". e.g. $ pip install --user -U pytest pytest-cov pyflakes
10
# or $ sage -pip install --user -U pytest pytest-cov pyflakes
11
# or inside the Sage environment: $ easy_install -U pytest
12
# $ easy_install -U pytest-cov
13
# $ easy_install -U pyflakes
14
# Second, call it in three ways, either
15
# $ ./test.sh to test all
16
# or
17
# $ ./test.sh coverage
18
# to test all and report test coverage
19
# or (for example)
20
# $ ./test.sh lmfdb/knowledge
21
# to test only a part of LMFDB
22
# To run tests with 3 cores in parallel, use
23
# $ ./test.sh -n 3
24
25
cd `dirname "$0"`
26
27
# get rid of all cached .pyc files!
28
find . -name '*.pyc' -delete
29
30
WHAT=''
31
COVER=''
32
33
if [[ "$1" == "coverage" ]]; then
34
rm -rf lmfdb/htmlcov
35
shift
36
COVER='--cov=lmfdb --cov-report html'
37
fi
38
39
WHAT="$@"
40
41
SAGE_COMMAND=$SAGE
42
if [[ "$SAGE_COMMAND" == "" ]]; then
43
SAGE_COMMAND=sage
44
fi
45
echo "Using Sage command $SAGE_COMMAND"
46
47
echo "Running pyflakes..."
48
read PYFLAKES_ERRCNT < <(find . | grep "\.py$" | xargs $SAGE_COMMAND -python -m pyflakes 2>&1 | tee /dev/stderr | grep "py:" -c)
49
if [[ $PYFLAKES_ERRCNT > 0 ]]; then
50
echo "WARNING: pyflakes reported $PYFLAKES_ERRCNT error(s)"
51
else
52
echo "pyflakes is happy"
53
fi
54
55
ARGS='-v -s'
56
57
if [[ -n $WHAT ]]; then
58
eval "$SAGE_COMMAND -python -m pytest $ARGS $COVER $WHAT"
59
else
60
eval "$SAGE_COMMAND -python -m pytest $ARGS $COVER lmfdb/"
61
fi
62
63
if [[ $PYFLAKES_ERRCNT > 0 ]]; then
64
printf "\nWARNING: pyflakes reported $PYFLAKES_ERRCNT error(s)\n"
65
fi
66
67