code: def test_stacked_ensemble_accepts_mixed_definition_of_base_models():
      """This test asserts that base models can be one of these:
      * list of models
      * GridSearch
      * list of GridSearches
      * list of Gridsearches and models
      """
  
      def _prepare_test_env():
          hyper_parameters = dict()
          hyper_parameters["ntrees"] = [1, 3, 5]
          params = dict(
              fold_assignment="modulo",
              nfolds=3,
              keep_cross_validation_predictions=True,
          )
  
          data = prepare_data()
  
          drf = H2ORandomForestEstimator(**params)
          drf.train(
              data.x, data.y, data.train, validation_frame=data.train
          )
  
          gs1 = H2OGridSearch(
              H2OGradientBoostingEstimator(**params),
              hyper_params=hyper_parameters,
          )
          gs1.train(
              data.x, data.y, data.train, validation_frame=data.train
          )
  
          gs2 = H2OGridSearch(
              H2ORandomForestEstimator(**params),
              hyper_params=hyper_parameters,
          )
          gs2.train(
              data.x, data.y, data.train, validation_frame=data.train
          )
  
          return dict(data=data, drf=drf, gs1=gs1, gs2=gs2)
  
      def test_base_models_work_properly_with_list_of_models():
          env = _prepare_test_env()
          se = H2OStackedEnsembleEstimator(base_models=[env["drf"]])
          se.train(env["data"].x, env["data"].y, env["data"].train)
          assert se.base_models == [
              env["drf"].model_id
          ], "StackedEnsembles don't work properly with single model in base models"
  
      def test_validation_on_backend_works():
          data = prepare_data()
          se = H2OStackedEnsembleEstimator(
              base_models=[data.train.frame_id]
          )
          try:
              se.train(data.x, data.y, data.train)
          except H2OResponseError as e:
              assert (
                  'Unsupported type "class water.fvec.Frame" as a base model.'
                  in str(e)
              ), "StackedEnsembles' base models validation exception probably changed."
          else:
              assert (
                  False
              ), "StackEnsembles' base models validation doesn't work properly."
  
      def _check_base_models(
          name, base_models_1, base_models_2, error_message
      ):
          def test():
              env = _prepare_test_env()
              se1 = H2OStackedEnsembleEstimator(
                  base_models=base_models_1(env), seed=seed
              )
              se1.train(env["data"].x, env["data"].y, env["data"].train)
              se2 = H2OStackedEnsembleEstimator(
                  base_models=base_models_2(env), seed=seed
              )
              se2.train(env["data"].x, env["data"].y, env["data"].train)
              assert sorted(se1.base_models) == sorted(
                  se2.base_models
              ), error_message
  
          test.__name__ = "test_stackedensembles_base_models_{}".format(
              name
          )
          return test
  
      test_cases = [
          {
              "name": "expand_single_grid",
              "base_models_1": lambda env: env["gs1"].models,
              "base_models_2": lambda env: env["gs1"],
              "error_message": "StackedEnsembles don't expand properly single grid.",
          },
          {
              "name": "expand_multiple_grids_in_list",
              "base_models_1": lambda env: env["gs1"].models
              + env["gs2"].models,
              "base_models_2": lambda env: [env["gs1"], env["gs2"]],
              "error_message": "StackedEnsembles don't expand properly multiple grids in a list.",
          },
          {
              "name": "expand_mixture_of_grids_and_models",
              "base_models_1": lambda env: env["gs1"].models
              + [env["drf"]]
              + env["gs2"].models,
              "base_models_2": lambda env: [
                  env["gs1"],
                  env["drf"],
                  env["gs2"],
              ],
              "error_message": "StackedEnsembles don't expand properly with mixture of grids and models.",
          },
          {
              "name": "expand_mixture_of_grid_ids_and_model_ids",
              "base_models_1": lambda env: env["gs1"].models
              + [env["drf"]]
              + env["gs2"].models,
              "base_models_2": lambda env: [
                  m.model_id
                  for m in env["gs1"].models
                  + [env["drf"]]
                  + env["gs2"].models
              ],
              "error_message": "StackedEnsembles don't work properly with mixture of grids id and model ids.",
          },
      ]
  
      return [
          test_base_models_work_properly_with_list_of_models,
          test_validation_on_backend_works,
      ] + [_check_base_models(**kwargs) for kwargs in test_cases]
  
file_path: h2o-3/h2o-py/tests/testdir_algos/stackedensemble/pyunit_stackedensemble_base_models.py
imports: import h2o
  import sys
  from h2o.grid import H2OGridSearch
  from h2o.estimators.random_forest import H2ORandomForestEstimator
  from h2o.estimators.gbm import H2OGradientBoostingEstimator
  from h2o.estimators.stackedensemble import H2OStackedEnsembleEstimator
  from h2o.exceptions import H2OResponseError
  from h2o import get_model
  from tests import pyunit_utils
label_desc: Use image node_id 6 for calling a global function with example usage: test_stacked_ensemble_accepts_mixed_definition_of_base_models() and returns: unknown, dict, test