Skip to content

Commit da46189

Browse files
committed
check enums that are lists
1 parent 834c1fa commit da46189

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/pynxtools/dataconverter/helpers.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -816,15 +816,25 @@ def validate_data_value(
816816
path, ValidationProblem.InvalidDatetime, value
817817
)
818818

819-
if nxdl_enum is not None and value not in nxdl_enum:
820-
if nxdl_enum_open:
821-
collector.collect_and_log(
822-
path, ValidationProblem.OpenEnumWithNewItem, nxdl_enum
823-
)
819+
if nxdl_enum is not None:
820+
if (
821+
isinstance(value, np.ndarray)
822+
and isinstance(nxdl_enum, list)
823+
and isinstance(nxdl_enum[0], list)
824+
):
825+
enum_value = list(value)
824826
else:
825-
collector.collect_and_log(
826-
path, ValidationProblem.InvalidEnum, nxdl_enum
827-
)
827+
enum_value = value
828+
829+
if enum_value not in nxdl_enum:
830+
if nxdl_enum_open:
831+
collector.collect_and_log(
832+
path, ValidationProblem.OpenEnumWithNewItem, nxdl_enum
833+
)
834+
else:
835+
collector.collect_and_log(
836+
path, ValidationProblem.InvalidEnum, nxdl_enum
837+
)
828838

829839
return value
830840

tests/dataconverter/test_validation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,8 @@ def format_error_message(msg: str) -> str:
457457
"NOT_TRUE_OR_FALSE",
458458
),
459459
[
460-
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/bool_value should be one of the following Python types: (<class 'bool'>, <class 'numpy.bool_'>), as defined in the NXDL as NX_BOOLEAN."
460+
"The value at /ENTRY[my_entry]/NXODD_name[nxodd_name]/bool_value should be one of the following Python types: "
461+
"(<class 'bool'>, <class 'numpy.bool_'>), as defined in the NXDL as NX_BOOLEAN."
461462
],
462463
id="string-instead-of-bool",
463464
),
@@ -1866,7 +1867,8 @@ def test_validate_data_dict(data_dict, error_messages, caplog, request):
18661867
"NOT_TRUE_OR_FALSE",
18671868
),
18681869
[
1869-
"The value at /my_entry/nxodd_name/bool_value should be one of the following Python types: (<class 'bool'>, <class 'numpy.bool_'>), as defined in the NXDL as NX_BOOLEAN."
1870+
"The value at /my_entry/nxodd_name/bool_value should be one of the following Python types: "
1871+
"(<class 'bool'>, <class 'numpy.bool_'>), as defined in the NXDL as NX_BOOLEAN."
18701872
],
18711873
id="string-instead-of-bool",
18721874
),

0 commit comments

Comments
 (0)