From 3f0ced73ed08c4e199b1d26123012fba168f1ea0 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Sat, 25 Apr 2020 11:58:17 +0200 Subject: [PATCH] test/osbuild: use StageInfo to verify stage opts Instead of manually loading the schema information of the stages and assemblers, use the new osbuild.meta.StageInfo class. --- test/test_osbuild.py | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/test/test_osbuild.py b/test/test_osbuild.py index 612e9a93..ee94b477 100644 --- a/test/test_osbuild.py +++ b/test/test_osbuild.py @@ -1,4 +1,3 @@ -import importlib.util import json import os import unittest @@ -79,26 +78,18 @@ class TestDescriptions(unittest.TestCase): }) def test_stageinfo(self): - def list_stages(base): - return [(base, f) for f in os.listdir(base) if f.startswith("org.osbuild")] + def list_stages(base, klass): + return [(klass, f) for f in os.listdir(base) if f.startswith("org.osbuild")] - def load_module(base, name): - loader = importlib.machinery.SourceFileLoader(name, f"{base}/{name}") - spec = importlib.util.spec_from_loader(loader.name, loader) - mod = importlib.util.module_from_spec(spec) - loader.exec_module(mod) - return mod - - stages = list_stages("stages") - stages += list_stages("assemblers") + stages = list_stages("stages", "Stage") + stages += list_stages("assemblers", "Assembler") for stage in stages: - base, name = stage - m = load_module(base, name) + klass, name = stage try: - json.loads("{" + m.STAGE_OPTS + "}") + osbuild.meta.StageInfo.load(os.curdir, klass, name) except json.decoder.JSONDecodeError as e: - msg = f"Stage '{base}/{name}' has invalid STAGE_OPTS\n\t" + str(e) + msg = f"{klass} '{name}' has invalid STAGE_OPTS\n\t" + str(e) self.fail(msg) def test_validation(self):