code: def test_keep_cross_validation_predictions_on_gbm_grid():
      kcvp = "keep_cross_validation_predictions"
      nfolds = 5
  
      def test_defaults():
          print("\n=== " + kcvp + " default behaviour ===")
          grid_search = setup_grid()
          train = prepare_data()
          grid_search.train(
              x=range(4), y=4, training_frame=train, nfolds=nfolds
          )
          keys = list_keys_in_memory()
          predictions = len(keys["cv_predictions"])
          assert (
              predictions == 0
          ), "{preds} CV predictions were not cleaned from memory".format(
              preds=predictions
          )
          for m in grid_search.models:
              assert not m.cross_validation_predictions(), (
                  "unexpected cv predictions for model " + m
              )
  
      def test_property_enabled():
          print("\n=== enabling " + kcvp + " ===")
          grid_search = setup_grid()
          train = prepare_data()
          grid_search.train(
              x=range(4),
              y=4,
              training_frame=train,
              nfolds=nfolds,
              keep_cross_validation_predictions=True,
          )
          keys = list_keys_in_memory()
          predictions = len(keys["cv_predictions"])
          expected = len(grid_search.models) * (
              nfolds + 1
          )  # +1 for holdout prediction
          assert (
              predictions == expected
          ), "missing CV predictions in memory, got {actual}, expected {expected}".format(
              actual=predictions, expected=expected
          )
          for m in grid_search.models:
              assert m.cross_validation_predictions(), (
                  "missing cv predictions for model " + m
              )
  
      def test_property_disabled():
          print("\n=== disabling " + kcvp + " ===")
          grid_search = setup_grid()
          train = prepare_data()
          grid_search.train(
              x=range(4),
              y=4,
              training_frame=train,
              nfolds=nfolds,
              keep_cross_validation_predictions=False,
          )
          keys = list_keys_in_memory()
          predictions = len(keys["cv_predictions"])
          assert (
              predictions == 0
          ), "{preds} CV predictions were not cleaned from memory".format(
              preds=predictions
          )
          for m in grid_search.models:
              assert not m.cross_validation_predictions(), (
                  "unexpected cv predictions for model " + m
              )
  
      test_defaults()
      test_property_enabled()
      test_property_disabled()
  
file_path: h2o-3/h2o-py/tests/testdir_algos/gbm/pyunit_gbm_grid_memory_cleanup.py
imports: import sys
  from collections import OrderedDict
  import re
  import h2o
  from tests import pyunit_utils
  from h2o.grid.grid_search import H2OGridSearch
  from h2o.estimators.gbm import H2OGradientBoostingEstimator
label_desc: Use image node_id 4 for calling a global function with example usage: test_keep_cross_validation_predictions_on_gbm_grid() without return types