From 740ef86d31c488daa284bcfd1da24eacddf0313d Mon Sep 17 00:00:00 2001 From: Don Cross Date: Mon, 13 Feb 2023 12:30:16 -0500 Subject: [PATCH] Run `mypy` to verify Python data types. --- .github/workflows/astronomy-engine-tests.yml | 4 ++-- generate/unit_test_python | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/astronomy-engine-tests.yml b/.github/workflows/astronomy-engine-tests.yml index 5721c0b3..02c79b28 100644 --- a/.github/workflows/astronomy-engine-tests.yml +++ b/.github/workflows/astronomy-engine-tests.yml @@ -19,8 +19,8 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.7 - - name: Install Python linter - run: python -m pip install --upgrade pip && pip install pylint + - name: Install Python tools + run: python -m pip install --upgrade pip && pip install pylint mypy - name: Install documentation tools Linux if: startsWith(matrix.os, 'ubuntu') run: sudo apt install -y doxygen xsltproc diff --git a/generate/unit_test_python b/generate/unit_test_python index 7017578f..653e3518 100755 --- a/generate/unit_test_python +++ b/generate/unit_test_python @@ -8,7 +8,17 @@ Fail() [[ "$1" == "" || "$1" == "-v" ]] || Fail "Invalid command line options." python3 --version || Fail "Cannot print python version" + +echo "$0: running pylint" python3 -m pylint --init-hook="import sys; sys.setrecursionlimit(2000)" ../source/python/astronomy/astronomy.py || Fail "pylint detected problems" + +echo "$0: running mypy" +cd ../source/python/astronomy || Fail "error changing to Python source directory" +mypy -m astronomy || Fail "error checking types using mypy" +cd ../../../generate || Fail "error changing back to generate directory" +echo "" + +echo "$0: running unit tests" python3 test.py $1 all || Fail "Failed Python unit tests." for file in temp/py_longitude_*.txt; do ./generate $1 check ${file} || Fail "Failed verification of file ${file}"