@@ -87,8 +87,9 @@ class ValidationProblem(Enum):
8787 UnitWithoutDocumentation = auto ()
8888 InvalidUnit = auto ()
8989 InvalidEnum = auto ()
90- OpenEnumWithCorrectNewItem = auto ()
91- OpenEnumWithIncorrectNewItem = auto ()
90+ OpenEnumWithCustom = auto ()
91+ OpenEnumWithCustomFalse = auto ()
92+ OpenEnumWithMissingCustom = auto ()
9293 MissingRequiredGroup = auto ()
9394 MissingRequiredField = auto ()
9495 MissingRequiredAttribute = auto ()
@@ -153,22 +154,22 @@ def _log(self, path: str, log_type: ValidationProblem, value: Optional[Any], *ar
153154
154155 elif log_type == ValidationProblem .InvalidEnum :
155156 logger .warning (
156- f"The value at { path } should be one of the following: { value } ."
157+ f"The value ' { args [ 0 ] } ' at { path } should be one of the following: { value } ."
157158 )
158- elif log_type == ValidationProblem .OpenEnumWithCorrectNewItem :
159+ elif log_type == ValidationProblem .OpenEnumWithCustom :
159160 logger .info (
160161 f"The value '{ args [0 ]} ' at { path } does not match with the enumerated items from the open enumeration: { value } ."
161162 )
162- elif log_type == ValidationProblem .OpenEnumWithIncorrectNewItem :
163- actual_value , custom_attr = args
164-
165- log_text = f"The value ' { actual_value } ' at { path } does not match with the enumerated items from the open enumeration: { value } ."
166- if custom_attr == "custom_missing" :
167- log_text += f" When a different value is used, a boolean 'custom' attribute must be added."
168- logger .warning ( log_text )
169- elif custom_attr == "custom_false" :
170- log_text += f" When a different value is used, the boolean 'custom' attribute cannot be False ."
171- logger . warning ( log_text )
163+ elif log_type == ValidationProblem .OpenEnumWithCustomFalse :
164+ logger . warning (
165+ f"The value ' { args [ 0 ] } ' at { path } does not match with the enumerated items from the open enumeration: { value } ."
166+ "When a different value is used, the boolean 'custom' attribute cannot be False ."
167+ )
168+ elif log_type == ValidationProblem . OpenEnumWithMissingCustom :
169+ logger .info (
170+ f"The value ' { args [ 0 ] } ' at { path } does not match with the enumerated items from the open enumeration: { value } . "
171+ " When a different value is used, a boolean 'custom=True ' attribute must be added. It was added here automatically ."
172+ )
172173
173174 elif log_type == ValidationProblem .MissingRequiredGroup :
174175 logger .warning (f"The required group { path } hasn't been supplied." )
@@ -301,7 +302,8 @@ def collect_and_log(
301302 ValidationProblem .UnitWithoutDocumentation ,
302303 ValidationProblem .CompressionStrengthZero ,
303304 ValidationProblem .MissingNXclass ,
304- ValidationProblem .OpenEnumWithCorrectNewItem ,
305+ ValidationProblem .OpenEnumWithCustom ,
306+ ValidationProblem .OpenEnumWithMissingCustom ,
305307 ):
306308 if self .logging and message not in self .data ["info" ]:
307309 self ._log (path , log_type , value , * args , ** kwargs )
@@ -819,10 +821,8 @@ def convert_int_to_float(value):
819821def is_valid_data_field (value : Any , nxdl_type : str , path : str ) -> Any :
820822 """Checks whether a given value is valid according to the type defined in the NXDL."""
821823
822- def validate_data_value (
823- value : Any , nxdl_type : str , nxdl_enum : list , nxdl_enum_open : bool , path : str
824- ) -> Any :
825- """Validate and possibly convert a primitive value according to NXDL type/enum rules."""
824+ def validate_data_value (value : Any , nxdl_type : str , path : str ) -> Any :
825+ """Validate and possibly convert a primitive value according to NXDL type rules."""
826826 accepted_types = NEXUS_TO_PYTHON_DATA_TYPES [nxdl_type ]
827827 original_value = value
828828
@@ -853,26 +853,6 @@ def validate_data_value(
853853 path , ValidationProblem .InvalidDatetime , value
854854 )
855855
856- # if nxdl_enum is not None:
857- # if (
858- # isinstance(value, np.ndarray)
859- # and isinstance(nxdl_enum, list)
860- # and isinstance(nxdl_enum[0], list)
861- # ):
862- # enum_value = list(value)
863- # else:
864- # enum_value = value
865-
866- # if enum_value not in nxdl_enum:
867- # if nxdl_enum_open:
868- # collector.collect_and_log(
869- # path, ValidationProblem.OpenEnumWithNewItem, nxdl_enum
870- # )
871- # else:
872- # collector.collect_and_log(
873- # path, ValidationProblem.InvalidEnum, nxdl_enum
874- # )
875-
876856 return value
877857
878858 if isinstance (value , dict ) and set (value .keys ()) == {"compress" , "strength" }:
@@ -888,18 +868,14 @@ def validate_data_value(
888868 path , ValidationProblem .InvalidCompressionStrength , value
889869 )
890870 # In this case, we remove the compression.
891- return validate_data_value (
892- value ["compress" ], nxdl_type , nxdl_enum , nxdl_enum_open , path
893- )
871+ return validate_data_value (value ["compress" ], nxdl_type , path )
894872
895873 # Apply standard validation to compressed value
896- value ["compress" ] = validate_data_value (
897- compressed_value , nxdl_type , nxdl_enum , nxdl_enum_open , path
898- )
874+ value ["compress" ] = validate_data_value (compressed_value , nxdl_type , path )
899875
900876 return value
901877
902- return validate_data_value (value , nxdl_type , nxdl_enum , nxdl_enum_open , path )
878+ return validate_data_value (value , nxdl_type , path )
903879
904880
905881def split_class_and_name_of (name : str ) -> tuple [Optional [str ], str ]:
0 commit comments