| 1 | #!/bin/bash |
| 2 | # -*- coding: utf-8 -*- |
| 3 | # BSD 2-Clause License |
| 4 | # |
| 5 | # Apprise - Push Notification Library. |
| 6 | # Copyright (c) 2026, Chris Caron <[email protected]> |
| 7 | # |
| 8 | # Redistribution and use in source and binary forms, with or without |
| 9 | # modification, are permitted provided that the following conditions are met: |
| 10 | # |
| 11 | # 1. Redistributions of source code must retain the above copyright notice, |
| 12 | # this list of conditions and the following disclaimer. |
| 13 | # |
| 14 | # 2. Redistributions in binary form must reproduce the above copyright notice, |
| 15 | # this list of conditions and the following disclaimer in the documentation |
| 16 | # and/or other materials provided with the distribution. |
| 17 | # |
| 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | # POSSIBILITY OF SUCH DAMAGE. |
| 29 | |
| 30 | # Absolute path to this script, e.g. /home/user/bin/foo.sh |
| 31 | SCRIPT=$(readlink -f "$0") |
| 32 | |
| 33 | # Absolute path this script is in, thus /home/user/bin |
| 34 | SCRIPTPATH=$(dirname "$SCRIPT") |
| 35 | |
| 36 | PYTHONPATH="" |
| 37 | |
| 38 | FOUNDROOT=1 |
| 39 | if [ -f "$(dirname $SCRIPTPATH)/pyproject.toml" ]; then |
| 40 | pushd "$(dirname $SCRIPTPATH)" &>/dev/null |
| 41 | FOUNDROOT=$? |
| 42 | PYTHONPATH="$(dirname $SCRIPTPATH)" |
| 43 | |
| 44 | elif [ -f "$SCRIPTPATH/pyproject.toml" ]; then |
| 45 | pushd "$SCRIPTPATH" &>/dev/null |
| 46 | FOUNDROOT=$? |
| 47 | PYTHONPATH="$SCRIPTPATH" |
| 48 | fi |
| 49 | |
| 50 | if [ $FOUNDROOT -ne 0 ]; then |
| 51 | echo "Error: Could not locate Apprise pyproject.toml file." |
| 52 | exit 1 |
| 53 | fi |
| 54 | |
| 55 | # Tidy previous reports (if present) |
| 56 | [ -d .coverage-reports ] && rm -rf .coverage-reports |
| 57 | |
| 58 | # This is a useful tool for checking for any lint errors and additionally |
| 59 | # checking the overall coverage. |
| 60 | which ruff &>/dev/null |
| 61 | [ $? -ne 0 ] && \ |
| 62 | echo "Missing ruff; make sure it is installed:" && \ |
| 63 | echo " > pip install ruff" && \ |
| 64 | exit 1 |
| 65 | |
| 66 | which coverage &>/dev/null |
| 67 | [ $? -ne 0 ] && \ |
| 68 | echo "Missing coverage; make sure it is installed:" && |
| 69 | echo " > pip install pytest-cov coverage" && \ |
| 70 | exit 1 |
| 71 | |
| 72 | echo "Performing PEP8 check..." |
| 73 | LANG=C.UTF-8 PYTHONPATH=$PYTHONPATH ruff check |
| 74 | if [ $? -ne 0 ]; then |
| 75 | echo "PEP8 check failed" |
| 76 | exit 1 |
| 77 | fi |
| 78 | echo "PEP8 check succeeded; no errors found! :)" |
| 79 | echo |
| 80 | |
| 81 | # Run our unit test coverage check |
| 82 | echo "Running test coverage check..." |
| 83 | pushd $PYTHONPATH &>/dev/null |
| 84 | if [ ! -z "$@" ]; then |
| 85 | LANG=C.UTF-8 PYTHONPATH=$PYTHONPATH coverage run -m pytest -vv -k "$@" |
| 86 | RET=$? |
| 87 | |
| 88 | else |
| 89 | LANG=C.UTF-8 PYTHONPATH=$PYTHONPATH coverage run -m pytest -vv |
| 90 | RET=$? |
| 91 | fi |
| 92 | |
| 93 | if [ $RET -ne 0 ]; then |
| 94 | echo "Tests failed." |
| 95 | exit 1 |
| 96 | fi |
| 97 | |
| 98 | # Build our report |
| 99 | LANG=C.UTF-8 PYTHONPATH=$PYTHONPATH coverage combine |
| 100 | |
| 101 | # Prepare XML Reference |
| 102 | LANG=C.UTF-8 PYTHONPATH=$PYTHONPATH coverage xml |
| 103 | |
| 104 | # Print our report |
| 105 | LANG=C.UTF-8 PYTHONPATH=$PYTHONPATH coverage report --show-missing |