From 3cd587e5e61a679f42b3780c2334fe256808109b Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 6 Jan 2025 17:18:25 +0100 Subject: [PATCH] sources: add sources_schema() helper This helper fixture will give access to the schema of the sources. With that we can easily test if the validations work as expected. --- sources/test/conftest.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/sources/test/conftest.py b/sources/test/conftest.py index e7f6e019..f4efa29a 100644 --- a/sources/test/conftest.py +++ b/sources/test/conftest.py @@ -4,6 +4,7 @@ from types import ModuleType import pytest +import osbuild.meta from osbuild import sources, testutil from osbuild.testutil.imports import import_module_from_path @@ -31,3 +32,23 @@ def sources_service(sources_module) -> ModuleType: fd = testutil.make_fake_service_fd() srv_obj = service_cls.from_args(["--service-fd", str(fd)]) return srv_obj + + +@pytest.fixture +def sources_schema(request: pytest.FixtureRequest) -> osbuild.meta.Schema: + """ + source_schema is a fixture returns the schema for a sources module. + """ + if hasattr(request, "param") and not isinstance(request.param, str): + raise ValueError( + "sources_schema fixture may be indirectly parametrized only with the sources schema version string") + + if not hasattr(request.module, "SOURCES_NAME"): + raise ValueError("sources_schema fixture must be used in a test module that defines SOURCES_NAME") + + sources_name = request.module.SOURCES_NAME + schema_version = request.param if hasattr(request, "param") else "2" + caller_dir = pathlib.Path(request.node.fspath).parent + root = caller_dir.parent.parent + mod_info = osbuild.meta.ModuleInfo.load(root, "Source", sources_name) + return osbuild.meta.Schema(mod_info.get_schema(version=schema_version), sources_name)