code: def test_CrossValidateByTrial(self) -> None:
      # With only 1 trial
      ma = mock.MagicMock()
      ma.get_training_data = mock.MagicMock(
          "ax.modelbridge.base.ModelBridge.get_training_data",
          autospec=True,
          return_value=self.training_data[1:3],
      )
      with self.assertRaises(ValueError):
          cross_validate_by_trial(model=ma)
      # Prepare input and output data
      ma = mock.MagicMock()
      ma.get_training_data = mock.MagicMock(
          "ax.modelbridge.base.ModelBridge.get_training_data",
          autospec=True,
          return_value=self.training_data,
      )
      ma.cross_validate = mock.MagicMock(
          "ax.modelbridge.base.ModelBridge.cross_validate",
          autospec=True,
          return_value=self.observation_data,
      )
      # Non-existent trial
      with self.assertRaises(ValueError):
          cross_validate_by_trial(model=ma, trial=10)
  
      # Working
      result = cross_validate_by_trial(model=ma)
      self.assertEqual(len(result), 1)
  
      # Check that ModelBridge.cross_validate was called correctly.
      z = ma.cross_validate.mock_calls
      self.assertEqual(len(z), 1)
      train_trials = [
          obs.features.trial_index
          for obs in z[0][2]["cv_training_data"]
      ]
      test_trials = [
          obsf.trial_index for obsf in z[0][2]["cv_test_points"]
      ]
      self.assertEqual(train_trials, [0, 1])
      self.assertEqual(test_trials, [2])
  
      # Check result is correct
      self.assertEqual(len(result), 1)
      self.assertEqual(result[0].observed.features.trial_index, 2)
  
imports: from typing import List
  from unittest import mock
  import numpy
  from ax.core.metric import Metric
  from ax.core.objective import MultiObjective, Objective
  from ax.core.observation import Observation, ObservationData, ObservationFeatures
  from ax.core.optimization_config import MultiObjectiveOptimizationConfig, OptimizationConfig
  from ax.core.outcome_constraint import OutcomeConstraint
  from ax.core.types import ComparisonOp
  from ax.modelbridge.cross_validation import assess_model_fit, compute_diagnostics, cross_validate, cross_validate_by_trial, CVDiagnostics, CVResult, has_good_opt_config_model_fit, SingleDiagnosticBestModelSelector
  from ax.modelbridge.registry import Models
  from ax.utils.common.testutils import TestCase
  from ax.utils.testing.core_stubs import get_branin_experiment
label_desc: Use image node_id 3 for calling the CrossValidationTest obj's underlying member method code with example usage: obj.test_CrossValidateByTrial() without return types