code: def test_callback_list_with_stateful_callback(tmp_path):
      """Checks that a callback list saves and restores all callbacks contained
      inside it."""
  
      callbacks = CallbackList([Callback(), StatefulCallback()])
      for i in range(3):
          callbacks.on_trial_result(
              iteration=i, trials=None, trial=None, result=None
          )
  
      callbacks.save_to_dir(str(tmp_path))
  
      assert list(
          tmp_path.glob(CallbackList.CKPT_FILE_TMPL.format("*"))
      )
      assert callbacks.can_restore(str(tmp_path))
  
      restored_callbacks = CallbackList(
          [Callback(), StatefulCallback()]
      )
      restored_callbacks.restore_from_dir(str(tmp_path))
  
      assert restored_callbacks._callbacks[1].counter == 3
  
file_path: ray/python/ray/tune/tests/test_callbacks.py
imports: import pytest
  from typing import Dict, Optional
  from ray.tune.callback import Callback, CallbackList
label_desc: Use image node_id 1 for calling a global function with example usage: test_callback_list_with_stateful_callback(tmp_path) without return types