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 + )