code: def test_checkpoint_callbacks_are_last(tmpdir):
      """Test that checkpoint callbacks always get moved to the end of the list, with preserved order."""
      checkpoint1 = ModelCheckpoint(tmpdir, monitor="foo")
      checkpoint2 = ModelCheckpoint(tmpdir, monitor="bar")
      model_summary = ModelSummary()
      early_stopping = EarlyStopping(monitor="foo")
      lr_monitor = LearningRateMonitor()
      progress_bar = TQDMProgressBar()
  
      # no model reference
      trainer = Trainer(
          callbacks=[
              checkpoint1,
              progress_bar,
              lr_monitor,
              model_summary,
              checkpoint2,
          ]
      )
      assert trainer.callbacks == [
          progress_bar,
          lr_monitor,
          model_summary,
          checkpoint1,
          checkpoint2,
      ]
  
      # no model callbacks
      model = LightningModule()
      model.configure_callbacks = lambda: []
      trainer.strategy._lightning_module = model
      cb_connector = _CallbackConnector(trainer)
      cb_connector._attach_model_callbacks()
      assert trainer.callbacks == [
          progress_bar,
          lr_monitor,
          model_summary,
          checkpoint1,
          checkpoint2,
      ]
  
      # with model-specific callbacks that substitute ones in Trainer
      model = LightningModule()
      model.configure_callbacks = lambda: [
          checkpoint1,
          early_stopping,
          model_summary,
          checkpoint2,
      ]
      trainer = Trainer(
          callbacks=[progress_bar, lr_monitor, ModelCheckpoint(tmpdir)]
      )
      trainer.strategy._lightning_module = model
      cb_connector = _CallbackConnector(trainer)
      cb_connector._attach_model_callbacks()
      assert trainer.callbacks == [
          progress_bar,
          lr_monitor,
          early_stopping,
          model_summary,
          checkpoint1,
          checkpoint2,
      ]
  
      # with tuner-specific callbacks that substitute ones in Trainer
      model = LightningModule()
      batch_size_finder = BatchSizeFinder()
      model.configure_callbacks = lambda: [
          checkpoint2,
          early_stopping,
          batch_size_finder,
          model_summary,
          checkpoint1,
      ]
      trainer = Trainer(callbacks=[progress_bar, lr_monitor])
      trainer.strategy._lightning_module = model
      cb_connector = _CallbackConnector(trainer)
      cb_connector._attach_model_callbacks()
      assert trainer.callbacks == [
          batch_size_finder,
          progress_bar,
          lr_monitor,
          early_stopping,
          model_summary,
          checkpoint2,
          checkpoint1,
      ]
  
imports: import contextlib
  import logging
  from unittest import mock
  from unittest.mock import Mock
  import pytest
  import torch
  from lightning.fabric.utilities.imports import _PYTHON_GREATER_EQUAL_3_8_0, _PYTHON_GREATER_EQUAL_3_10_0
  from lightning.pytorch import Callback, LightningModule, Trainer
  from lightning.pytorch.callbacks import EarlyStopping, GradientAccumulationScheduler, LearningRateMonitor, ModelCheckpoint, ModelSummary, ProgressBar, TQDMProgressBar
  from lightning.pytorch.callbacks.batch_size_finder import BatchSizeFinder
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.trainer.connectors.callback_connector import _CallbackConnector
label_desc: Use image node_id 1 for calling a global function with example usage: test_checkpoint_callbacks_are_last(tmpdir) without return types