From 5cb2da55f16e21e82048cdf11f73e988bf33ef3f Mon Sep 17 00:00:00 2001 From: Simon de Vlieger Date: Wed, 17 Aug 2022 11:39:04 +0200 Subject: [PATCH] test: run mypy in test-src not in GH actions --- .github/workflows/checks.yml | 12 ------------ test/src/test_pylint.py | 11 +++++++++++ test/test.py | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 526943b4..0155e903 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -74,15 +74,3 @@ jobs: -k autopep8 \ --rootdir=. \ -v - - mypy: - name: "Mypy check" - runs-on: ubuntu-latest - steps: - - name: Clone repo - uses: actions/checkout@v2 - - name: Check files with mypy - run: | - sudo apt install python3-pip -y - sudo pip install mypy types-pyyaml jsonschema mako - mypy osbuild diff --git a/test/src/test_pylint.py b/test/src/test_pylint.py index c2f37130..5dc0ede9 100644 --- a/test/src/test_pylint.py +++ b/test/src/test_pylint.py @@ -57,6 +57,17 @@ def test_pylint(source_files): pytest.fail("pylint issues detected") +@pytest.mark.skipif(not test.TestBase.have_mypy(), reason="mypy not available") +def test_mypy(): + # + # Run `mypy` on osbuild sources. + # + + r = subprocess.run(["mypy", "osbuild/"], check=False) + if r.returncode != 0: + pytest.fail("mypy issues detected") + + @pytest.mark.skipif(not test.TestBase.have_autopep8(), reason="autopep8 not available") def test_autopep8(source_files): r = subprocess.run(["autopep8-3", "--diff", "--exit-code"] + source_files, check=False) diff --git a/test/test.py b/test/test.py index 366c4666..f3fa22c1 100644 --- a/test/test.py +++ b/test/test.py @@ -185,6 +185,24 @@ class TestBase(unittest.TestCase): return r.returncode == 0 and "autopep8" in r.stdout + @staticmethod + def have_mypy() -> bool: + """Check mypy Availability + + This checks whether `mypy` is available in the current path and + can be called by this process. + """ + + try: + r = subprocess.run( + ["mypy", "--version"], + encoding="utf-8", stdout=subprocess.PIPE, check=False + ) + except FileNotFoundError: + return False + + return r.returncode == 0 and "mypy" in r.stdout + @staticmethod def have_rpm_ostree() -> bool: """Check rpm-ostree Availability