Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sanbrock committed Oct 17, 2024
1 parent be74186 commit f0ce8fa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/pynxtools/nomad/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def parse(

# TODO: domain experiment could also be registered
if archive.metadata is None:
archine.metadata = EntryMetadata()
archive.metadata = EntryMetadata()

# Normalise experiment type
app_def = str(self.nx_root).split("(")[1].split(")")[0].split(",")[0]
Expand Down
8 changes: 4 additions & 4 deletions tests/nexus/test_nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@

import logging
import os
import pytest
import numpy as np

import lxml.etree as ET
import numpy as np
import pytest

from pynxtools.definitions.dev_tools.utils.nxdl_utils import (
get_inherited_nodes,
get_node_at_nxdl_path,
get_nx_attribute_type,
get_nx_classes,
get_nx_units,
)
from pynxtools.nexus.nexus import decode_if_string
from pynxtools.nexus.nexus import HandleNexus
from pynxtools.nexus.nexus import HandleNexus, decode_if_string

logger = logging.getLogger(__name__)

Expand Down
37 changes: 20 additions & 17 deletions tests/nomad/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,44 @@

from pynxtools.nomad.parser import NexusParser
from pynxtools.nomad.schema import nexus_metainfo_package

__REPLACEMENT_FOR_NX = "BS"
from pynxtools.nomad.utils import __REPLACEMENT_FOR_NX
from pynxtools.nomad.utils import __rename_nx_to_nomad as rename_nx_to_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(rename_nx_to_nomad("NXentry") + ".nx_kind", "group"),
pytest.param(rename_nx_to_nomad("NXdetector") + ".real_time__field", "*"),
pytest.param(rename_nx_to_nomad("NXentry") + ".DATA.nx_optional", True),
pytest.param(rename_nx_to_nomad("NXentry") + ".DATA.nx_kind", "group"),
pytest.param(rename_nx_to_nomad("NXentry") + ".DATA.nx_optional", True),
pytest.param(
f"{__REPLACEMENT_FOR_NX}detector.real_time__field.name", "real_time__field"
rename_nx_to_nomad("NXdetector") + ".real_time__field.name",
"real_time__field",
),
pytest.param(
f"{__REPLACEMENT_FOR_NX}detector.real_time__field.nx_type", "NX_NUMBER"
rename_nx_to_nomad("NXdetector") + ".real_time__field.nx_type", "NX_NUMBER"
),
pytest.param(
f"{__REPLACEMENT_FOR_NX}detector.real_time__field.nx_units", "NX_TIME"
rename_nx_to_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(rename_nx_to_nomad("NXarpes") + ".ENTRY.DATA.nx_optional", False),
pytest.param(rename_nx_to_nomad("NXentry") + ".nx_category", "base"),
pytest.param(
f"{__REPLACEMENT_FOR_NX}dispersion_table.refractive_index__field.nx_type",
rename_nx_to_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",
rename_nx_to_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"),
pytest.param(rename_nx_to_nomad("NXapm") + ".nx_category", "application"),
],
)
def test_assert_nexus_metainfo(path: str, value: Any):
Expand Down Expand Up @@ -125,7 +128,7 @@ def test_nexus_example():

example_data = "src/pynxtools/data/201805_WSe2_arpes.nxs"
NexusParser().parse(example_data, archive, get_logger(__name__))
arpes_obj = getattr(archive.nexus, f"{__REPLACEMENT_FOR_NX}arpes")
arpes_obj = getattr(archive.data, rename_nx_to_nomad("NXarpes"))

assert arpes_obj.ENTRY[0].SAMPLE[0].pressure__field == ureg.Quantity(
"3.27e-10*millibar"
Expand Down

0 comments on commit f0ce8fa

Please sign in to comment.