Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sanbrock committed Jan 21, 2025
1 parent 274e0d6 commit 27fa71c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
22 changes: 10 additions & 12 deletions src/pynxtools/nomad/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,12 @@ def _to_section(

nomad_def_name = rename_nx_for_nomad(nomad_def_name, is_group=True)

# for groups, get the definition from the package
new_def = current.m_def.all_sub_sections[nomad_def_name]

new_section: MSection = None # type:ignore

for section in current.m_get_sub_sections(new_def):
if hdf_name is None or getattr(section, "nx_name", None) == hdf_name:
new_section = section
break

if new_section is not None:
return new_section
if current == nx_root:
# for groups, get the definition from the package
new_def = current.m_def.all_sub_sections["ENTRY"]
for section in current.m_get_sub_sections(new_def):
if hdf_name is None or getattr(section, "nx_name", None) == hdf_name:
return section
cls = getattr(nexus_schema, nx_def, None)
sec = cls()
new_def_spec = sec.m_def.all_sub_sections[nomad_def_name]
Expand All @@ -117,6 +110,11 @@ def _to_section(
current.ENTRY.append(new_section)
new_section.__dict__["nx_name"] = hdf_name
else:
# for groups, get the definition from the package
new_def = current.m_def.all_sub_sections[nomad_def_name]
for section in current.m_get_sub_sections(new_def):
if hdf_name is None or getattr(section, "nx_name", None) == hdf_name:
return section
current.m_create(new_def.section_def.section_cls)
new_section = current.m_get_sub_section(new_def, -1)
new_section.__dict__["nx_name"] = hdf_name
Expand Down
8 changes: 4 additions & 4 deletions tests/nomad/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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.data, rename_nx_for_nomad("NXarpes"))
arpes_obj = archive.data

assert arpes_obj.ENTRY[0].SAMPLE[0].pressure__field == ureg.Quantity(
"3.27e-10*millibar"
Expand Down Expand Up @@ -94,9 +94,9 @@ 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, rename_nx_for_nomad("NXlauetof"))
lauetof_obj = archive.data

assert lauetof_obj.entry.name__group.time_of_flight__field == ureg.Quantity(
assert lauetof_obj.ENTRY[0].name__group.time_of_flight__field == ureg.Quantity(
"1.0*second"
)
assert lauetof_obj.entry.sample.name__field == "SAMPLE-CHAR-DATA"
assert lauetof_obj.ENTRY[0].sample.name__field == "SAMPLE-CHAR-DATA"

0 comments on commit 27fa71c

Please sign in to comment.