code: def testCallbacksEndToEnd(self):
      def train_fn(config):
          if config["do"] == "save":
              with tune.checkpoint_dir(0):
                  pass
              tune.report(metric=1)
          elif config["do"] == "fail":
              raise RuntimeError("I am failing on purpose.")
          elif config["do"] == "delay":
              time.sleep(2)
              tune.report(metric=20)
  
      config = {"do": tune.grid_search(["save", "fail", "delay"])}
  
      tune.run(
          train_fn,
          config=config,
          raise_on_failed_trial=False,
          callbacks=[self.callback],
      )
  
      self.assertIn("setup", self.callback.state)
      self.assertTrue(self.callback.state["setup"] is not None)
      keys = Experiment.PUBLIC_KEYS.copy()
      keys.add("total_num_samples")
      for key in keys:
          self.assertIn(key, self.callback.state["setup"])
      # check if it was added first
      self.assertTrue(list(self.callback.state)[0] == "setup")
      self.assertEqual(
          self.callback.state["trial_fail"]["trial"].config["do"],
          "fail",
      )
      self.assertEqual(
          self.callback.state["trial_save"]["trial"].config["do"],
          "save",
      )
      self.assertEqual(
          self.callback.state["trial_result"]["trial"].config["do"],
          "delay",
      )
      self.assertEqual(
          self.callback.state["trial_complete"]["trial"].config["do"],
          "delay",
      )
      self.assertIn("experiment_end", self.callback.state)
      # check if it was added last
      self.assertTrue(list(self.callback.state)[-1] == "experiment_end")
  
imports: import os
  import shutil
  import sys
  import tempfile
  import time
  import unittest
  from unittest.mock import patch
  from collections import OrderedDict
  import ray
  from ray import tune
  from ray.air._internal.checkpoint_manager import _TrackedCheckpoint, CheckpointStorage
  from ray.air.constants import TRAINING_ITERATION
  from ray.rllib import _register_all
  from ray.tune.execution.ray_trial_executor import _ExecutorEvent, _ExecutorEventType, RayTrialExecutor
  from ray.tune.callback import warnings
  from ray.tune.experiment import Trial
  from ray.tune.execution.trial_runner import TrialRunner
  from ray.tune import Callback
  from ray.tune.experiment import Experiment
label_desc: Use image node_id 4 for calling the TrialRunnerCallbacks obj's underlying member method code with example usage: obj.testCallbacksEndToEnd() without return types