From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202508 header.b=VCoWNIIK; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 52FEA5A0621 for ; Thu, 02 Oct 2025 07:04:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202508; t=1759381478; bh=NE9KyQAw0Q5IPsahNNVVPuh6Popk0h6HmZ6RaKbC2z0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VCoWNIIKQmKZBjRP8Q1VaEQ6dSPnSzL/rUpD5CSDgvHNeiHO7I0Qz+bPmF7HDXJRs qZerJzRljhbatvSuiuLBx/WQCPFhK+C59hxV6gN4fKsMl4nHxlKzPVXpaNjs2xsVrL qR1Uo6aEuziIBLknd6hTEj2zFLZWuDUVD9/RaLsE+MzAoAb4LAMKu04mXbqJ40Gt6n 6liqXxVHfCUdOHsypvgZYqGPaIF9KA6mL3+A4r2Soib2MiCjMOp8otQu/7WnD6ZgPh Hyo7SSCJRXiQKvzBC0aJEiHC85XgKrhSwGe/4YR+rEBntuh8ynPhQObdq8F5+GxArV 5UCei6WOwjYaQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ccfqB5mPvz4wDR; Thu, 2 Oct 2025 15:04:38 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v3 6/6] test: Add linting of Python test scripts Date: Thu, 2 Oct 2025 15:04:37 +1000 Message-ID: <20251002050437.4175553-7-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251002050437.4175553-1-david@gibson.dropbear.id.au> References: <20251002050437.4175553-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: NT3XMJNYYVCBPADPWIOYDI6U3JNHJASM X-Message-ID-Hash: NT3XMJNYYVCBPADPWIOYDI6U3JNHJASM X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- test/Makefile | 15 ++++++++++++++- test/build/build.py | 5 +++-- test/build/static_checkers.sh | 6 +++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/test/Makefile b/test/Makefile index 3800a0a9..5b5f0fc1 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 e49287c9..e3de8305 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 42806e79..228b99ae 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 "$@" -- 2.51.0