Skip to content

Commit

Permalink
Merge pull request #26 from FAIRmat-NFDI/25-parametrise-test-with-the…
Browse files Browse the repository at this point in the history
…-reader-directories

Parametrise reader test
  • Loading branch information
lukaspie authored Mar 25, 2024
2 parents ac2768b + 161ad27 commit bd80363
Showing 1 changed file with 41 additions and 17 deletions.
58 changes: 41 additions & 17 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import xml.etree.ElementTree as ET
from glob import glob
import pytest

from pynxtools.dataconverter.helpers import (
generate_template_from_nxdl,
Expand All @@ -14,7 +15,32 @@
from pynxtools_xps.reader import XPSReader


def test_example_data():
@pytest.mark.parametrize(
"reader_dir",
[
# pytest.param(
# "spe",
# id="Phi .spe reader",
# ),
# pytest.param(
# "pro",
# id="Phi .pro reader",
# ),
pytest.param(
"vms_regular",
id="Regular VAMAS reader",
),
pytest.param(
"vms_irregular",
id="Irregular VAMAS reader",
),
pytest.param(
"xml",
id="Specs XML reader",
),
],
)
def test_example_data(reader_dir):
"""
Test the example data for the XPS reader
"""
Expand All @@ -24,27 +50,25 @@ def test_example_data():
def_dir = get_nexus_definitions_path()

data_dir = os.path.join(os.path.dirname(__file__), "data")
reader_dir = os.path.join(data_dir, reader_dir)

reader_dirs = sorted(glob(os.path.join(data_dir, "*")))

for reader_dir in reader_dirs:
input_files = sorted(glob(os.path.join(reader_dir, "*")))
input_files = sorted(glob(os.path.join(reader_dir, "*")))

for supported_nxdl in reader.supported_nxdls:
nxdl_file = os.path.join(
def_dir, "contributed_definitions", f"{supported_nxdl}.nxdl.xml"
)
for supported_nxdl in reader.supported_nxdls:
nxdl_file = os.path.join(
def_dir, "contributed_definitions", f"{supported_nxdl}.nxdl.xml"
)

root = ET.parse(nxdl_file).getroot()
template = Template()
generate_template_from_nxdl(root, template)
root = ET.parse(nxdl_file).getroot()
template = Template()
generate_template_from_nxdl(root, template)

read_data = reader().read(
template=Template(template), file_paths=tuple(input_files)
)
read_data = reader().read(
template=Template(template), file_paths=tuple(input_files)
)

assert isinstance(read_data, Template)
assert validate_data_dict(template, read_data, root)
assert isinstance(read_data, Template)
assert validate_data_dict(template, read_data, root)


## This will be implemented in the future.
Expand Down

0 comments on commit bd80363

Please sign in to comment.