From c68385826195908057265aeacbe74e71519da157 Mon Sep 17 00:00:00 2001 From: Ben Vincent Date: Sun, 17 May 2026 11:41:50 +1000 Subject: [PATCH] test: validate all metadata.yaml files against schema in pytest --- pyproject.toml | 2 ++ tests/test_metadata.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tests/test_metadata.py diff --git a/pyproject.toml b/pyproject.toml index 76677c9..c8cc4f9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,4 +6,6 @@ requires-python = ">=3.11" [dependency-groups] dev = [ "pytest>=8", + "jsonschema>=4", + "pyyaml>=6", ] diff --git a/tests/test_metadata.py b/tests/test_metadata.py new file mode 100644 index 0000000..533b0eb --- /dev/null +++ b/tests/test_metadata.py @@ -0,0 +1,36 @@ +"""Validate every rpms/*/metadata.yaml against schema/metadata.json.""" + +import json +from pathlib import Path + +import jsonschema +import pytest +import yaml + +REPO_ROOT = Path(__file__).parent.parent +SCHEMA_FILE = REPO_ROOT / "schema" / "metadata.json" +RPMS_DIR = REPO_ROOT / "rpms" + + +@pytest.fixture(scope="session") +def schema(): + with open(SCHEMA_FILE) as f: + return json.load(f) + + +def metadata_files(): + return sorted(RPMS_DIR.glob("*/metadata.yaml")) + + +@pytest.mark.parametrize("metadata_file", metadata_files(), ids=lambda p: p.parent.name) +def test_metadata_valid(metadata_file, schema): + with open(metadata_file) as f: + data = yaml.safe_load(f) + + validator = jsonschema.Draft7Validator(schema) + errors = sorted(validator.iter_errors(data), key=str) + + assert not errors, "\n".join( + f" {'.'.join(str(p) for p in e.absolute_path) or '(root)'}: {e.message}" + for e in errors + )