8000 Fixes enumeration check by domna · Pull Request #313 · FAIRmat-NFDI/pynxtools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fixes enumeration check #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions pynxtools/dataconverter/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,12 @@ def convert_data_dict_path_to_hdf5_path(path) -> str:
return hdf5path


def is_value_valid_element_of_enum(value, elem) -> Tuple[bool, list]:
def is_value_valid_element_of_enum(value, elist) -> Tuple[bool, list]:
"""Checks whether a value has to be specific from the NXDL enumeration and returns options."""
if elem is not None:
has_enums, enums = nexus.get_enums(elem)
if has_enums and (
isinstance(value, list) or value not in enums[0:-1] or value == ""
):
return False, enums
for elem in elist:
enums = nexus.get_enums(elem)
if enums is not None:
return value in enums, enums
return True, []


Expand Down Expand Up @@ -465,7 +463,7 @@ def check_optionality_based_on_parent_group(path, nxdl_path, nxdl_root, data, te
if is_nxdl_path_a_child(
nxdl_path, optional_parent_nxdl
) and not all_required_children_are_set(optional_parent, data, nxdl_root):
raise LookupError(
logger.warning(
f"The data entry, {path}, has an optional parent, "
f"{optional_parent}, with required children set. Either"
f" provide no children for {optional_parent} or provide"
Expand Down Expand Up @@ -617,9 +615,12 @@ def validate_data_dict(template, data, nxdl_root: ET.Element):
else "NXDL_TYPE_UNAVAILABLE"
)
data[path] = is_valid_data_field(data[path], nxdl_type, path)
is_valid_enum, enums = is_value_valid_element_of_enum(data[path], elem)
elist = nexus.get_inherited_nodes(
nxdl_path, path.rsplit("/", 1)[-1], nxdl_root
)[2]
is_valid_enum, enums = is_value_valid_element_of_enum(data[path], elist)
if not is_valid_enum:
raise ValueError(
logger.warning(
f"The value at {path} should be on of the "
f"following strings: {enums}"
)
Expand Down
2 changes: 1 addition & 1 deletion pynxtools/definitions
Submodule definitions updated 50 files
+10 −10 contributed_definitions/NXapm.nxdl.xml
+2 −2 contributed_definitions/NXapm_charge_state_analysis.nxdl.xml
+152 −0 contributed_definitions/NXapm_compositionspace_config.nxdl.xml
+375 −0 contributed_definitions/NXapm_compositionspace_results.nxdl.xml
+1 −1 contributed_definitions/NXapm_paraprobe_intersector_config.nxdl.xml
+77 −47 contributed_definitions/NXapm_paraprobe_nanochem_config.nxdl.xml
+66 −49 contributed_definitions/NXapm_paraprobe_nanochem_results.nxdl.xml
+1 −1 contributed_definitions/NXcg_primitive_set.nxdl.xml
+2 −2 contributed_definitions/NXcrystal_structure.nxdl.xml
+3 −3 contributed_definitions/NXdelocalization.nxdl.xml
+1 −6 contributed_definitions/NXebeam_column.nxdl.xml
+1 −1 contributed_definitions/NXevent_data_apm.nxdl.xml
+1 −1 contributed_definitions/NXgraph_edge_set.nxdl.xml
+1 −1 contributed_definitions/NXgraph_node_set.nxdl.xml
+1 −1 contributed_definitions/NXion.nxdl.xml
+6 −6 contributed_definitions/NXlens_em.nxdl.xml
+1 −1 contributed_definitions/NXms.nxdl.xml
+1 −1 contributed_definitions/NXms_feature_set.nxdl.xml
+3 −3 contributed_definitions/NXms_recon.nxdl.xml
+1 −1 contributed_definitions/NXms_score_results.nxdl.xml
+6 −6 contributed_definitions/NXms_snapshot_set.nxdl.xml
+1 −1 contributed_definitions/NXoptical_system_em.nxdl.xml
+9 −9 contributed_definitions/NXunit_cell.nxdl.xml
+11 −11 contributed_definitions/nyaml/NXapm.yaml
+2 −2 contributed_definitions/nyaml/NXapm_charge_state_analysis.yaml
+0 −879 contributed_definitions/nyaml/NXapm_composition_space_results.yaml
+94 −0 contributed_definitions/nyaml/NXapm_compositionspace_config.yaml
+275 −0 contributed_definitions/nyaml/NXapm_compositionspace_results.yaml
+1 −1 contributed_definitions/nyaml/NXapm_paraprobe_intersector_config.yaml
+63 −33 contributed_definitions/nyaml/NXapm_paraprobe_nanochem_config.yaml
+53 −40 contributed_definitions/nyaml/NXapm_paraprobe_nanochem_results.yaml
+1 −1 contributed_definitions/nyaml/NXcg_primitive_set.yaml
+2 −2 contributed_definitions/nyaml/NXcrystal_structure.yaml
+3 −3 contributed_definitions/nyaml/NXdelocalization.yaml
+1 −1 contributed_definitions/nyaml/NXebeam_column.yaml
+1 −1 contributed_definitions/nyaml/NXevent_data_apm.yaml
+1 −1 contributed_definitions/nyaml/NXgraph_edge_set.yaml
+1 −1 contributed_definitions/nyaml/NXgraph_node_set.yaml
+1 −1 contributed_definitions/nyaml/NXion.yaml
+6 −6 contributed_definitions/nyaml/NXlens_em.yaml
+1 −1 contributed_definitions/nyaml/NXms.yaml
+2 −2 contributed_definitions/nyaml/NXms_feature_set.yaml
+3 −3 contributed_definitions/nyaml/NXms_recon.yaml
+1 −1 contributed_definitions/nyaml/NXms_score_results.yaml
+2 −2 contributed_definitions/nyaml/NXms_snapshot_set.yaml
+1 −1 contributed_definitions/nyaml/NXoptical_system_em.yaml
+4 −4 contributed_definitions/nyaml/NXunit_cell.yaml
+59 −3 dev_tools/tests/test_nxdl_utils.py
+70 −34 dev_tools/utils/nxdl_utils.py
+17 −0 manual/source/classes/contributed_definitions/apm-structure.rst
2 changes: 1 addition & 1 deletion pynxtools/nexus-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2020.10-1637-g2ac33b2cf
v2020.10-1652-g88ff21539
10 changes: 9 additions & 1 deletion tests/dataconverter/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def fixture_filled_test_data(template, tmp_path):
),
(
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type should be on of the following"
" strings: [1st type,2nd type,3rd type,4th type]"
" strings: ['1st type', '2nd type', '3rd type', '4th type']"
),
id="wrong-enum-choice",
),
Expand Down Expand Up @@ -430,6 +430,14 @@ def test_validate_data_dict(
captured_logs = caplog.records
helpers.validate_data_dict(template, data_dict, nxdl_root)
assert any(error_message in rec.message for rec in captured_logs)
elif request.node.callspec.id in (
"wrong-enum-choice",
"atleast-one-required-child-not-provided-optional-parent",
):
with caplog.at_level(logging.WARNING):
helpers.validate_data_dict(template, data_dict, nxdl_root)

assert error_message in caplog.text
else:
with pytest.raises(Exception) as execinfo:
helpers.validate_data_dict(template, data_dict, nxdl_root)
Expand Down
0