Skip to content

Commit d761f37

Browse files
authored
Merge branch 'master' into fix-required-under-optional
2 parents b4686fc + df8001b commit d761f37

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

pynxtools/dataconverter/helpers.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,12 @@ def convert_data_dict_path_to_hdf5_path(path) -> str:
264264
return hdf5path
265265

266266

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

277275

@@ -624,9 +622,12 @@ def validate_data_dict(template, data, nxdl_root: ET.Element):
624622
else "NXDL_TYPE_UNAVAILABLE"
625623
)
626624
data[path] = is_valid_data_field(data[path], nxdl_type, path)
627-
is_valid_enum, enums = is_value_valid_element_of_enum(data[path], elem)
625+
elist = nexus.get_inherited_nodes(
626+
nxdl_path, path.rsplit("/", 1)[-1], nxdl_root
627+
)[2]
628+
is_valid_enum, enums = is_value_valid_element_of_enum(data[path], elist)
628629
if not is_valid_enum:
629-
raise ValueError(
630+
logger.warning(
630631
f"The value at {path} should be on of the "
631632
f"following strings: {enums}"
632633
)

pynxtools/definitions

Submodule definitions updated 50 files

pynxtools/nexus-version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2020.10-1637-g2ac33b2cf
1+
v2020.10-1652-g88ff21539

tests/dataconverter/test_helpers.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def fixture_filled_test_data(template, tmp_path):
335335
),
336336
(
337337
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/type should be on of the following"
338-
" strings: [1st type,2nd type,3rd type,4th type]"
338+
" strings: ['1st type', '2nd type', '3rd type', '4th type']"
339339
),
340340
id="wrong-enum-choice",
341341
),
@@ -445,6 +445,14 @@ def test_validate_data_dict(
445445
captured_logs = caplog.records
446446
helpers.validate_data_dict(template, data_dict, nxdl_root)
447447
assert any(error_message in rec.message for rec in captured_logs)
448+
elif request.node.callspec.id in (
449+
"wrong-enum-choice",
450+
"atleast-one-required-child-not-provided-optional-parent",
451+
):
452+
with caplog.at_level(logging.WARNING):
453+
helpers.validate_data_dict(template, data_dict, nxdl_root)
454+
455+
assert error_message in caplog.text
448456
else:
449457
with pytest.raises(Exception) as execinfo:
450458
helpers.validate_data_dict(template, data_dict, nxdl_root)

0 commit comments

Comments
 (0)