code: def test_checkpoint_hook_register(tmpdir):
      from speechbrain.utils.checkpoints import (
          register_checkpoint_hooks,
      )
      from speechbrain.utils.checkpoints import mark_as_saver
      from speechbrain.utils.checkpoints import mark_as_loader
      from speechbrain.utils.checkpoints import Checkpointer
  
      # First a proper interface:
      @register_checkpoint_hooks
      class CustomRecoverable:
          def __init__(self, param):
              self.param = int(param)
  
          @mark_as_saver
          def save(self, path):
              with open(path, "w") as fo:
                  fo.write(str(self.param))
  
          @mark_as_loader
          def load(self, path, end_of_epoch):
              del end_of_epoch  # Unused
              with open(path) as fi:
                  self.param = int(fi.read())
  
      recoverable = CustomRecoverable(1.0)
      checkpointer = Checkpointer(tmpdir, {"recoverable": recoverable})
      checkpointer.save_checkpoint()
      recoverable.param = 2.0
      checkpointer.recover_if_possible()
      assert recoverable.param == 1.0
  
      # Improper interfaces:
      with pytest.raises(TypeError):
  
          class BadRecoverable:
              def __init__(self, param):
                  self.param = int(param)
  
              def save(self, path):
                  with open(path, "w") as fo:
                      fo.write(str(self.param))
  
              @mark_as_loader
              def load(self, path):  # MISSING end_of_epoch
                  with open(path) as fi:
                      self.param = int(fi.read())
  
      with pytest.raises(TypeError):
  
          class BadRecoverable:  # noqa: F811
              def __init__(self, param):
                  self.param = int(param)
  
              @mark_as_saver
              def save(self, path, extra_arg):  # Extra argument
                  with open(path, "w") as fo:
                      fo.write(str(self.param))
  
              def load(self, path, end_of_epoch):
                  del end_of_epoch  # Unused
                  with open(path) as fi:
                      self.param = int(fi.read())
  
file_path: speechbrain/tests/unittests/test_checkpoints.py
imports: import torch
  import pytest
label_desc: Use image node_id 7 for calling a global function with example usage: test_checkpoint_hook_register(tmpdir) without return types