aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2025-10-02 15:04:37 +1000
committerStefano Brivio <sbrivio@redhat.com>2025-10-07 15:33:38 +0200
commit2a16cdf3e605a1c72647ccd520106a1e59ec8d50 (patch)
tree85970de99800068f961a1b046da1025108198309
parent81fd66a31e44a07ee98f22946104f951245123e5 (diff)
downloadpasst-2a16cdf3e605a1c72647ccd520106a1e59ec8d50.tar
passt-2a16cdf3e605a1c72647ccd520106a1e59ec8d50.tar.gz
passt-2a16cdf3e605a1c72647ccd520106a1e59ec8d50.tar.bz2
passt-2a16cdf3e605a1c72647ccd520106a1e59ec8d50.tar.lz
passt-2a16cdf3e605a1c72647ccd520106a1e59ec8d50.tar.xz
passt-2a16cdf3e605a1c72647ccd520106a1e59ec8d50.tar.zst
passt-2a16cdf3e605a1c72647ccd520106a1e59ec8d50.zip
test: Add linting of Python test scripts
We currently have one test moved to the new exeter based framwork written in Python. We plan to add many more, so add linting (flake8) and type checking (mypy) of those scripts. This can be invoked manually with "make flake8" or "make mypy" in test/, and is also added to the static checkers test set. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--test/Makefile15
-rwxr-xr-xtest/build/build.py5
-rwxr-xr-xtest/build/static_checkers.sh6
3 files changed, 22 insertions, 4 deletions
diff --git a/test/Makefile b/test/Makefile
index 3800a0a..5b5f0fc 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -8,6 +8,8 @@
BATS = bats -j $(shell nproc)
EXETOOL = exeter/exetool/exetool
WGET = wget -c
+FLAKE8 = flake8
+MYPY = mypy --strict
DEBIAN_IMGS = debian-8.11.0-openstack-amd64.qcow2 \
debian-10-nocloud-amd64.qcow2 \
@@ -64,11 +66,15 @@ LOCAL_ASSETS = mbuto.img mbuto.mem.img podman/bin/podman QEMU_EFI.fd \
ASSETS = $(DOWNLOAD_ASSETS) $(LOCAL_ASSETS)
EXETER_PYPATH = exeter/py3
+EXETER_PYTHON = build/build.py
EXETER_BATS = smoke/smoke.sh.bats \
- build/build.py.bats build/static_checkers.sh.bats
+ $(EXETER_PYTHON:%=%.bats) build/static_checkers.sh.bats
BATS_FILES = $(EXETER_BATS) \
podman/test/system/505-networking-pasta.bats
+# Python test code (for linters)
+PYPKGS = $(EXETER_PYTHON)
+
CFLAGS = -Wall -Werror -Wextra -pedantic -std=c99
assets: $(ASSETS)
@@ -127,6 +133,12 @@ medium.bin:
big.bin:
dd if=/dev/urandom bs=1M count=10 of=$@
+flake8: pull-exeter
+ PYTHONPATH=$(EXETER_PYPATH) $(FLAKE8) $(PYPKGS)
+
+mypy: pull-exeter
+ PYTHONPATH=$(EXETER_PYPATH) $(MYPY) $(PYPKGS)
+
$(EXETER_BATS): %.bats: % $(EXETOOL)
PYTHONPATH=$(EXETER_PYPATH) $(EXETOOL) bats -- $< > $@
@@ -141,6 +153,7 @@ debug: assets
clean:
rm -f perf.js *~
+ rm -rf .mypy_cache
rm -f $(LOCAL_ASSETS)
rm -f $(EXETER_BATS)
rm -rf test_logs
diff --git a/test/build/build.py b/test/build/build.py
index e49287c..e3de830 100755
--- a/test/build/build.py
+++ b/test/build/build.py
@@ -18,11 +18,12 @@ import os
from pathlib import Path
import subprocess
import tempfile
-from typing import Iterable, Iterator
+from typing import Iterator
import exeter
-def sh(cmd):
+
+def sh(cmd: str) -> None:
"""Run given command in a shell"""
subprocess.run(cmd, shell=True)
diff --git a/test/build/static_checkers.sh b/test/build/static_checkers.sh
index 42806e7..228b99a 100755
--- a/test/build/static_checkers.sh
+++ b/test/build/static_checkers.sh
@@ -21,6 +21,10 @@ exeter_set_description cppcheck "passt sources pass cppcheck"
exeter_register clang_tidy make -C .. clang-tidy
exeter_set_description clang_tidy "passt sources pass clang-tidy"
-exeter_main "$@"
+exeter_register flake8 make flake8
+exeter_set_description flake8 "passt tests in Python pass flake8"
+exeter_register mypy make mypy
+exeter_set_description mypy "passt tests in Python pass mypy --strict"
+exeter_main "$@"