code: def test_clearml_saver_callbacks():
      mock_task = MagicMock(spec=clearml.Task)
      mock_task.name = "check-task"
  
      mock_model = MagicMock(spec=clearml.OutputModel)
  
      model_info = WeightsFileHandler.ModelInfo(
          model=mock_model,
          upload_filename="test.pt",
          local_model_path="",
          local_model_id="",
          framework=Framework.pytorch,
          task=mock_task,
      )
  
      mock_model_info = MagicMock(spec_set=model_info)
  
      # Simulate 4 calls to save model and 2 to remove (n_saved=2)
      filenames = [
          "best_model_5_val_acc=0.123.pt",
          "best_model_6_val_acc=0.234.pt",
          "best_model_7_val_acc=0.356.pt",
          "best_model_8_val_acc=0.456.pt",
      ]
      metadata_list = [
          {
              "basename": "best_model",
              "score_name": "val_acc",
              "priority": 0.123,
          },
          {
              "basename": "best_model",
              "score_name": "val_acc",
              "priority": 0.234,
          },
          {
              "basename": "best_model",
              "score_name": "val_acc",
              "priority": 0.345,
          },
          {
              "basename": "best_model",
              "score_name": "val_acc",
              "priority": 0.456,
          },
      ]
      dirname = "/tmp/test"
  
      _checkpoint_slots = defaultdict(list)
  
      n_saved = 2
  
      for i, (filename, metadata) in enumerate(
          zip(filenames, metadata_list)
      ):
          mock_model_info.upload_filename = filename
  
          if i >= n_saved:
              # Remove
              filename_to_remove = filenames[i % n_saved]
              for slots in _checkpoint_slots.values():
                  try:
                      slots[slots.index(filename_to_remove)] = None
                  except ValueError:
                      pass
                  else:
                      i = i % n_saved
                      break
  
          basename = metadata["basename"]
          checkpoint_key = (dirname, basename)
  
          context = ClearMLSaver._CallbacksContext(
              callback_type=WeightsFileHandler.CallbackType,
              slots=_checkpoint_slots[checkpoint_key],
              checkpoint_key=str(checkpoint_key),
              filename=filename,
              basename=basename,
              metadata=metadata,
          )
  
          output_model_info = context.pre_callback(
              str(WeightsFileHandler.CallbackType.save), mock_model_info
          )
          assert (
              hasattr(output_model_info, "upload_filename")
              and f"{basename}_{i}.pt"
              in output_model_info.upload_filename
          )
          assert (
              hasattr(output_model_info, "local_model_id")
              and str(checkpoint_key)
              in output_model_info.local_model_id
          )
  
          output_model_info = context.post_callback(
              str(WeightsFileHandler.CallbackType.save), mock_model_info
          )
          assert hasattr(output_model_info, "model") and hasattr(
              output_model_info.model, "name"
          )
          assert hasattr(output_model_info, "model") and hasattr(
              output_model_info.model, "comment"
          )
          assert (
              isinstance(output_model_info.model.name, str)
              and filename in output_model_info.model.name
          )
          assert (
              isinstance(output_model_info.model.comment, str)
              and metadata["basename"]
              in output_model_info.model.comment
              and metadata["score_name"]
              in output_model_info.model.comment
          )
  
imports: import math
  import os
  from collections import defaultdict
  from unittest.mock import ANY, call, MagicMock, patch
  import clearml
  import pytest
  import torch
  from clearml.binding.frameworks import WeightsFileHandler
  from clearml.model import Framework
  import ignite.distributed
  from ignite.contrib.handlers.clearml_logger import ClearMLLogger, ClearMLSaver, global_step_from_engine, GradsHistHandler, GradsScalarHandler, OptimizerParamsHandler, OutputHandler, WeightsHistHandler, WeightsScalarHandler
  from ignite.engine import Engine, Events, State
  from ignite.handlers import Checkpoint
label_desc: Use image node_id 30 for calling a global function with example usage: test_clearml_saver_callbacks() without return types