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.
This commit is contained in:
parent
7a48c3b734
commit
fd21da3aa6
1 changed files with 26 additions and 25 deletions
|
|
@ -78,6 +78,14 @@ def runFileServer(barrier, directory):
|
||||||
httpd.serve_forever()
|
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):
|
def check_case(source, case, store, libdir):
|
||||||
expects = case["expects"]
|
expects = case["expects"]
|
||||||
if expects == "error":
|
if expects == "error":
|
||||||
|
|
@ -89,31 +97,24 @@ def check_case(source, case, store, libdir):
|
||||||
raise ValueError(f"invalid expectation: {expects}")
|
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")
|
@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")
|
sources = os.path.join(test.TestBase.locate_test_data(), "sources")
|
||||||
|
|
||||||
for source in os.listdir(sources):
|
with open(f"{sources}/{source}/cases/{case}") as f:
|
||||||
check_source(source, sources)
|
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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue