Skip to content

Commit

Permalink
use renaming function in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaspie committed Oct 18, 2024
1 parent c69c564 commit 6e34ffd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
40 changes: 18 additions & 22 deletions tests/nomad/test_metainfo_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,47 +28,43 @@
from typing import Any

from pynxtools.nomad.schema import nexus_metainfo_package
from pynxtools.nomad.utils import __REPLACEMENT_FOR_NX
from pynxtools.nomad.utils import __remove_nx_for_nomad as remove_nx_for_nomad


@pytest.mark.parametrize(
"path,value",
[
pytest.param("name", "nexus"),
pytest.param("NXobject.name", "NXobject"),
pytest.param(f"{__REPLACEMENT_FOR_NX}entry.nx_kind", "group"),
pytest.param(f"{__REPLACEMENT_FOR_NX}detector.real_time__field", "*"),
pytest.param(f"{__REPLACEMENT_FOR_NX}entry.DATA.nx_optional", True),
pytest.param(f"{__REPLACEMENT_FOR_NX}entry.DATA.nx_kind", "group"),
pytest.param(f"{__REPLACEMENT_FOR_NX}entry.DATA.nx_optional", True),
pytest.param(remove_nx_for_nomad("NXentry") + ".nx_kind", "group"),
pytest.param(remove_nx_for_nomad("NXdetector") + ".real_time__field", "*"),
pytest.param(remove_nx_for_nomad("NXentry") + ".DATA.nx_optional", True),
pytest.param(remove_nx_for_nomad("NXentry") + ".DATA.nx_kind", "group"),
pytest.param(remove_nx_for_nomad("NXentry") + ".DATA.nx_optional", True),
pytest.param(
f"{__REPLACEMENT_FOR_NX}detector.real_time__field.name", "real_time__field"
remove_nx_for_nomad("NXdetector") + ".real_time__field.name",
"real_time__field",
),
pytest.param(
f"{__REPLACEMENT_FOR_NX}detector.real_time__field.nx_type", "NX_NUMBER"
remove_nx_for_nomad("NXdetector") + ".real_time__field.nx_type", "NX_NUMBER"
),
pytest.param(
f"{__REPLACEMENT_FOR_NX}detector.real_time__field.nx_units", "NX_TIME"
remove_nx_for_nomad("NXdetector") + ".real_time__field.nx_units", "NX_TIME"
),
pytest.param(f"{__REPLACEMENT_FOR_NX}arpes.ENTRY.DATA.nx_optional", False),
pytest.param(f"{__REPLACEMENT_FOR_NX}entry.nx_category", "base"),
pytest.param(remove_nx_for_nomad("NXarpes") + ".ENTRY.DATA.nx_optional", False),
pytest.param(remove_nx_for_nomad("NXentry") + ".nx_category", "base"),
pytest.param(
f"{__REPLACEMENT_FOR_NX}dispersion_table.refractive_index__field.nx_type",
remove_nx_for_nomad("NXdispersion_table")
+ ".refractive_index__field.nx_type",
"NX_COMPLEX",
),
pytest.param(
f"{__REPLACEMENT_FOR_NX}dispersive_material.ENTRY.dispersion_x."
"DISPERSION_TABLE.refractive_index__field.nx_type",
remove_nx_for_nomad("NXdispersive_material")
+ ".ENTRY.dispersion_x."
+ "DISPERSION_TABLE.refractive_index__field.nx_type",
"NX_COMPLEX",
),
pytest.param(f"{__REPLACEMENT_FOR_NX}apm.nx_category", "application"),
# This checks that the renaming for unallowed group names works.
pytest.param(
f"{__REPLACEMENT_FOR_NX}lauetof.entry.name__group.nx_type", "NXdata"
),
pytest.param(
f"{__REPLACEMENT_FOR_NX}lauetof.entry.name__group.nx_name", "name"
),
pytest.param(remove_nx_for_nomad("NXapm") + ".nx_category", "application"),
],
)
def test_assert_nexus_metainfo(path: str, value: Any):
Expand Down
4 changes: 2 additions & 2 deletions tests/nomad/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@

from pynxtools.nomad.parser import NexusParser
from pynxtools.nomad.schema import nexus_metainfo_package
from pynxtools.nomad.utils import __REPLACEMENT_FOR_NX
from pynxtools.nomad.utils import __remove_nx_for_nomad as remove_nx_for_nomad


def test_nexus_example():
archive = EntryArchive()

Expand Down Expand Up @@ -93,7 +93,7 @@ def test_nexus_example_with_renamed_groups():
os.path.dirname(__file__), "../data/nomad/NXlauetof.hdf5"
)
NexusParser().parse(lauetof_data, archive, get_logger(__name__))
lauetof_obj = getattr(archive.data, f"{__REPLACEMENT_FOR_NX}lauetof")
lauetof_obj = getattr(archive.data, remove_nx_for_nomad("NXlauetof"))

assert lauetof_obj.entry.name__group.time_of_flight__field == ureg.Quantity(
"1.0*second"
Expand Down

0 comments on commit 6e34ffd

Please sign in to comment.