@@ -1060,47 +1060,44 @@ def _validate_single_criterion(
10601060 return condition_met , message
10611061
10621062
1063+ def _get_artifact_validation_results (
1064+ artifact : dict [str , Any ], expected_validations : list [dict [str , Any ]]
1065+ ) -> tuple [list [bool ], list [str ]]:
1066+ """
1067+ Checks one artifact against all validations and returns the boolean outcomes and messages.
1068+ """
1069+ artifact_name = artifact .get ("name" , "missing_artifact_name" )
1070+ custom_properties = artifact ["customProperties" ]
1071+
1072+ # Store the boolean results and informative messages
1073+ bool_results = []
1074+ messages = []
1075+
1076+ for validation in expected_validations :
1077+ condition_met , message = _validate_single_criterion (
1078+ artifact_name = artifact_name , custom_properties = custom_properties , validation = validation
1079+ )
1080+ bool_results .append (condition_met )
1081+ messages .append (message )
1082+
1083+ return bool_results , messages
1084+
1085+
10631086def validate_model_artifacts_match_criteria_and (
10641087 all_model_artifacts : list [dict [str , Any ]], expected_validations : list [dict [str , Any ]], model_name : str
10651088) -> bool :
10661089 """
1067- Validates that at least one artifact in the model satisfies all expected validation criteria.
1068-
1069- Args:
1070- all_model_artifacts: List of artifact dictionaries for a model
1071- expected_validations: List of validation criteria dictionaries, each containing:
1072- - key_name: The property name to validate
1073- - key_type: The type of the property (int_value, double_value, string_value)
1074- - comparison: The comparison type (exact, min, max, contains)
1075- - value: The expected value for comparison
1076- model_name: Name of the model being validated (for logging)
1077-
1078- Returns:
1079- bool: True if at least one artifact satisfies all validation criteria, False otherwise
1090+ Validates that at least one artifact in the model satisfies ALL expected validation criteria.
10801091 """
10811092 for artifact in all_model_artifacts :
1082- artifact_name = artifact .get ("name" , "missing_artifact_name" )
1083- custom_properties = artifact ["customProperties" ]
1084- validation_results = []
1085- conditions_passed = 0
1086-
1087- # Check if this artifact satisfies ALL validations
1088- for validation in expected_validations :
1089- condition_met , message = _validate_single_criterion (
1090- artifact_name = artifact_name , custom_properties = custom_properties , validation = validation
1091- )
1092-
1093- if not condition_met :
1094- validation_results .append (f"{ message } : failed" )
1095- break # AND logic: break on first failure
1096- else :
1097- validation_results .append (f"{ message } : passed" )
1098- conditions_passed += 1
1099-
1100- # If this artifact satisfies all conditions, the model passes
1101- if conditions_passed == len (expected_validations ):
1093+ bool_results , messages = _get_artifact_validation_results (
1094+ artifact = artifact , expected_validations = expected_validations
1095+ )
1096+ # If ALL results are True
1097+ if all (bool_results ):
1098+ validation_results = [f"{ message } : passed" for message in messages ]
11021099 LOGGER .info (
1103- f"Model { model_name } passed all { conditions_passed } validations with artifact: { validation_results } "
1100+ f"Model { model_name } passed all { len ( bool_results ) } validations with artifact: { validation_results } "
11041101 )
11051102 return True
11061103
@@ -1111,34 +1108,16 @@ def validate_model_artifacts_match_criteria_or(
11111108 all_model_artifacts : list [dict [str , Any ]], expected_validations : list [dict [str , Any ]], model_name : str
11121109) -> bool :
11131110 """
1114- Validates that at least one artifact in the model satisfies at least one of the expected validation criteria.
1115-
1116- Args:
1117- all_model_artifacts: List of artifact dictionaries for a model
1118- expected_validations: List of validation criteria dictionaries, each containing:
1119- - key_name: The property name to validate
1120- - key_type: The type of the property (int_value, double_value, string_value)
1121- - comparison: The comparison type (exact, min, max, contains)
1122- - value: The expected value for comparison
1123- model_name: Name of the model being validated (for logging)
1124-
1125- Returns:
1126- bool: True if at least one artifact satisfies at least one validation criterion, False otherwise
1111+ Validates that at least one artifact in the model satisfies AT LEAST ONE of the expected validation criteria.
11271112 """
11281113 for artifact in all_model_artifacts :
1129- artifact_name = artifact .get ("name" )
1130- custom_properties = artifact ["customProperties" ]
1131-
1132- # Check if this artifact satisfies ANY validation (OR logic)
1133- for validation in expected_validations :
1134- condition_met , message = _validate_single_criterion (
1135- artifact_name = artifact_name , custom_properties = custom_properties , validation = validation
1136- )
1137-
1138- if condition_met :
1139- LOGGER .info (f"Model { model_name } passed OR validation with artifact: { message } " )
1140- return True # OR logic: return immediately on first success
1114+ bool_results , messages = _get_artifact_validation_results (
1115+ artifact = artifact , expected_validations = expected_validations
1116+ )
1117+ if any (bool_results ):
1118+ # Find the first passing message for logging
1119+ LOGGER .info (f"Model { model_name } passed OR validation with artifact: { messages [bool_results .index (True )]} " )
1120+ return True
11411121
1142- # No artifact passed any validation
1143- LOGGER .info (f"Model { model_name } failed all { len (expected_validations )} OR validations" )
1122+ LOGGER .error (f"Model { model_name } failed all OR validations" )
11441123 return False
0 commit comments