| 1 | # SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | |
| 3 | import os |
| 4 | from subprocess import check_call |
| 5 | import sys |
| 6 | |
| 7 | |
| 8 | class TestLinters: |
| 9 | |
| 10 | def test_flake8_pkg(self): |
| 11 | check_call([sys.executable, "-m", "flake8", "qemu/"]) |
| 12 | |
| 13 | def test_flake8_scripts(self): |
| 14 | check_call([sys.executable, "-m", "flake8", "scripts/"]) |
| 15 | |
| 16 | def test_flake8_qapi(self): |
| 17 | check_call( |
| 18 | [ |
| 19 | sys.executable, |
| 20 | "-m", |
| 21 | "flake8", |
| 22 | "../scripts/qapi/", |
| 23 | "../docs/sphinx/qapidoc.py", |
| 24 | "../docs/sphinx/qapi_domain.py", |
| 25 | ] |
| 26 | ) |
| 27 | |
| 28 | def test_isort_minikconf(self): |
| 29 | check_call([sys.executable, "-m", "isort", "-c", "../scripts/minikconf.py"]) |
| 30 | |
| 31 | def test_isort_pkg(self): |
| 32 | check_call([sys.executable, "-m", "isort", "-c", "qemu/"]) |
| 33 | |
| 34 | def test_isort_scripts(self): |
| 35 | check_call([sys.executable, "-m", "isort", "-c", "scripts/"]) |
| 36 | |
| 37 | def test_isort_qapi(self): |
| 38 | check_call( |
| 39 | [ |
| 40 | sys.executable, |
| 41 | "-m", |
| 42 | "isort", |
| 43 | "--sp", |
| 44 | ".", |
| 45 | "-c", |
| 46 | "../scripts/qapi/", |
| 47 | ] |
| 48 | ) |
| 49 | |
| 50 | def test_isort_qapi_sphinx(self): |
| 51 | # Force isort to recognize 'compat' as a local module and not |
| 52 | # third-party |
| 53 | check_call( |
| 54 | [ |
| 55 | sys.executable, |
| 56 | "-m", |
| 57 | "isort", |
| 58 | "--sp", |
| 59 | ".", |
| 60 | "-c", |
| 61 | "-p", |
| 62 | "compat", |
| 63 | "../docs/sphinx/qapi_domain.py", |
| 64 | "../docs/sphinx/qapidoc.py", |
| 65 | ] |
| 66 | ) |
| 67 | |
| 68 | def test_mypy_minikconf(self): |
| 69 | check_call([sys.executable, "-m", "mypy", "../scripts/minikconf.py"]) |
| 70 | |
| 71 | def test_mypy_pkg(self): |
| 72 | check_call([sys.executable, "-m", "mypy", "-p", "qemu"]) |
| 73 | |
| 74 | def test_mypy_scripts(self): |
| 75 | check_call([sys.executable, "-m", "mypy", "scripts/"]) |
| 76 | |
| 77 | def test_mypy_qapi(self): |
| 78 | check_call([sys.executable, "-m", "mypy", "../scripts/qapi"]) |
| 79 | |
| 80 | def test_mypy_iotests(self): |
| 81 | check_call( |
| 82 | [sys.executable, "-m", "linters", "--mypy"], |
| 83 | cwd="../tests/qemu-iotests/", |
| 84 | ) |
| 85 | |
| 86 | # Setuptools v60 introduced the SETUPTOOLS_USE_DISTUTILS=stdlib |
| 87 | # workaround; stdlib distutils was fully removed in Python |
| 88 | # 3.12+. Once we are on >=3.12+ exclusively, this workaround can be |
| 89 | # dropped safely. Until then, it is needed for some versions on |
| 90 | # Fedora/Debian distributions which relied upon distro-patched |
| 91 | # setuptools present in CPython, but not within setuptools itself. |
| 92 | |
| 93 | def test_pylint_pkg(self): |
| 94 | os.environ["SETUPTOOLS_USE_DISTUTILS"] = "stdlib" |
| 95 | check_call([sys.executable, "-m", "pylint", "qemu/"]) |
| 96 | |
| 97 | def test_pylint_scripts(self): |
| 98 | os.environ["SETUPTOOLS_USE_DISTUTILS"] = "stdlib" |
| 99 | check_call([sys.executable, "-m", "pylint", "scripts/"]) |
| 100 | |
| 101 | def test_pylint_qapi(self): |
| 102 | os.environ["SETUPTOOLS_USE_DISTUTILS"] = "stdlib" |
| 103 | check_call( |
| 104 | [ |
| 105 | sys.executable, |
| 106 | "-m", |
| 107 | "pylint", |
| 108 | "--rcfile=../scripts/qapi/pylintrc", |
| 109 | "../scripts/qapi/", |
| 110 | "../docs/sphinx/qapidoc.py", |
| 111 | "../docs/sphinx/qapi_domain.py", |
| 112 | ] |
| 113 | ) |
| 114 | |
| 115 | def test_pylint_iotests(self): |
| 116 | os.environ["SETUPTOOLS_USE_DISTUTILS"] = "stdlib" |
| 117 | check_call( |
| 118 | [sys.executable, "-m", "linters", "--pylint"], |
| 119 | cwd="../tests/qemu-iotests/", |
| 120 | ) |