From fd21da3aa68f11f8fdc92c7d9c044eb4ff960347 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Tue, 27 Apr 2021 19:01:14 +0000 Subject: [PATCH] test/sources: use pytest.mark.parameterize Parameterize `test_sources` via `pytest.mark.parameterize`, so that now the product of source and test cases for that source is visible to pytest and thus also the caller. --- test/run/test_sources.py | 51 ++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/test/run/test_sources.py b/test/run/test_sources.py index 0b80c8be..ee3438c5 100644 --- a/test/run/test_sources.py +++ b/test/run/test_sources.py @@ -78,6 +78,14 @@ def runFileServer(barrier, directory): httpd.serve_forever() +def make_test_cases(): + sources = os.path.join(test.TestBase.locate_test_data(), "sources") + if os.path.exists(sources): + for source in os.listdir(sources): + for case in os.listdir(f"{sources}/{source}/cases"): + yield source, case + + def check_case(source, case, store, libdir): expects = case["expects"] if expects == "error": @@ -89,31 +97,24 @@ def check_case(source, case, store, libdir): raise ValueError(f"invalid expectation: {expects}") -def check_source(source, sources): - index = osbuild.meta.Index(os.curdir) - - for case in os.listdir(f"{sources}/{source}/cases"): - with open(f"{sources}/{source}/cases/{case}") as f: - case_options = json.load(f) - - info = index.get_module_info("Source", source) - desc = case_options[source] - items = desc.get("items", {}) - options = desc.get("options", {}) - - src = osbuild.sources.Source(info, items, options) - - with tempfile.TemporaryDirectory() as tmpdir, \ - osbuild.objectstore.ObjectStore(tmpdir) as store, \ - fileServer(test.TestBase.locate_test_data()): - check_case(src, case_options, store, index.path) - check_case(src, case_options, store, index.path) - - -@pytest.mark.skipif(not test.TestBase.have_test_data(), reason="no test-data access") @pytest.mark.skipif(not can_setup_netns(), reason="network namespace setup failed") -def test_sources(): +@pytest.mark.parametrize("source,case", make_test_cases()) +def test_sources(source, case): + index = osbuild.meta.Index(os.curdir) sources = os.path.join(test.TestBase.locate_test_data(), "sources") - for source in os.listdir(sources): - check_source(source, sources) + with open(f"{sources}/{source}/cases/{case}") as f: + case_options = json.load(f) + + info = index.get_module_info("Source", source) + desc = case_options[source] + items = desc.get("items", {}) + options = desc.get("options", {}) + + src = osbuild.sources.Source(info, items, options) + + with tempfile.TemporaryDirectory() as tmpdir, \ + osbuild.objectstore.ObjectStore(tmpdir) as store, \ + fileServer(test.TestBase.locate_test_data()): + check_case(src, case_options, store, index.path) + check_case(src, case_options, store, index.path)