def testMergeDetails(self):
        a = text_format.Parse(
            """
        validation_details {
          slicing_details {
            slicing_spec {}
            num_matching_slices: 1
          }
          slicing_details {
            slicing_spec {
              feature_keys: ["x", "y"]
            }
            num_matching_slices: 1
          }
        }""", validation_result_pb2.ValidationResult())

        b = text_format.Parse(
            """
        validation_details {
          slicing_details {
            slicing_spec {
              feature_keys: ["x"]
            }
            num_matching_slices: 1
          }
          slicing_details {
            slicing_spec {
              feature_keys: ["x", "y"]
            }
            num_matching_slices: 2
          }
        }""", validation_result_pb2.ValidationResult())

        expected = text_format.Parse(
            """
        validation_details {
          slicing_details {
            slicing_spec {}
            num_matching_slices: 1
          }
          slicing_details {
            slicing_spec {
              feature_keys: ["x", "y"]
            }
            num_matching_slices: 3
          }
          slicing_details {
            slicing_spec {
              feature_keys: ["x"]
            }
            num_matching_slices: 1
          }
        }""", validation_result_pb2.ValidationResult())

        metrics_validator.merge_details(a, b)
        self.assertProtoEquals(expected, a)
 def add_input(
     self, result: 'Optional[validation_result_pb2.ValidationResult]',
     new_input: 'Optional[validation_result_pb2.ValidationResult]'
 ) -> 'Optional[validation_result_pb2.ValidationResult]':
     if new_input is None:
         return None
     if result is None:
         result = validation_result_pb2.ValidationResult(validation_ok=True)
     result.validation_ok &= new_input.validation_ok
     result.metric_validations_per_slice.extend(
         new_input.metric_validations_per_slice)
     metrics_validator.merge_details(result, new_input)
     return result
 def merge_accumulators(
     self,
     accumulators: 'List[Optional[validation_result_pb2.ValidationResult]]'
 ) -> 'Optional[validation_result_pb2.ValidationResult]':
   accumulators = [accumulator for accumulator in accumulators if accumulator]
   if not accumulators:
     return None
   result = validation_result_pb2.ValidationResult(validation_ok=True)
   for new_input in accumulators:
     result.metric_validations_per_slice.extend(
         new_input.metric_validations_per_slice)
     metrics_validator.merge_details(result, new_input)
     result.validation_ok &= new_input.validation_ok
   return result
 def merge_accumulators(
     self,
     accumulators: 'Iterable[Optional[validation_result_pb2.ValidationResult]]'
 ) -> 'Optional[validation_result_pb2.ValidationResult]':
   it = iter(accumulators)
   result = next(it)
   for new_input in it:
     if new_input is None:
       continue
     if result is None:
       result = validation_result_pb2.ValidationResult(validation_ok=True)
     result.metric_validations_per_slice.extend(
         new_input.metric_validations_per_slice)
     metrics_validator.merge_details(result, new_input)
     result.validation_ok &= new_input.validation_ok
   return result