code: def test_trainer_datamodule_hook_system(tmpdir):
      """Test the LightningDataModule hook system."""
      model = BoringModel()
      batches = 2
      trainer = Trainer(
          default_root_dir=tmpdir,
          max_epochs=1,
          limit_train_batches=batches,
          limit_val_batches=batches,
          limit_test_batches=batches,
          limit_predict_batches=batches,
          enable_progress_bar=False,
          enable_model_summary=False,
          reload_dataloaders_every_n_epochs=1,
      )
  
      called = []
      dm = HookedDataModule(called)
      trainer.fit(model, datamodule=dm)
      expected = [
          {"name": "prepare_data"},
          {"name": "setup", "kwargs": {"stage": "fit"}},
          {"name": "val_dataloader"},
          {"name": "train_dataloader"},
          {"name": "state_dict"},
          {"name": "teardown", "kwargs": {"stage": "fit"}},
      ]
      assert called == expected
  
      called = []
      dm = HookedDataModule(called)
      trainer.validate(model, datamodule=dm, verbose=False)
      expected = [
          {"name": "prepare_data"},
          {"name": "setup", "kwargs": {"stage": "validate"}},
          {"name": "val_dataloader"},
          {"name": "teardown", "kwargs": {"stage": "validate"}},
      ]
      assert called == expected
  
      called = []
      dm = HookedDataModule(called)
      trainer.test(model, datamodule=dm, verbose=False)
      expected = [
          {"name": "prepare_data"},
          {"name": "setup", "kwargs": {"stage": "test"}},
          {"name": "test_dataloader"},
          {"name": "teardown", "kwargs": {"stage": "test"}},
      ]
      assert called == expected
  
      called = []
      dm = HookedDataModule(called)
      trainer.predict(model, datamodule=dm)
      expected = [
          {"name": "prepare_data"},
          {"name": "setup", "kwargs": {"stage": "predict"}},
          {"name": "predict_dataloader"},
          {"name": "teardown", "kwargs": {"stage": "predict"}},
      ]
      assert called == expected
  
imports: from functools import partial, update_wrapper
  from inspect import getmembers, isfunction
  from unittest import mock
  from unittest.mock import ANY, PropertyMock
  import pytest
  import torch
  from lightning.fabric.utilities.imports import _TORCH_GREATER_EQUAL_2_0
  from lightning.pytorch import Callback, LightningDataModule, LightningModule, Trainer, __version__
  from lightning.pytorch.demos.boring_classes import BoringDataModule, BoringModel, RandomDataset
  from lightning.pytorch.utilities.model_helpers import is_overridden
  from torch import Tensor
  from torch.utils.data import DataLoader
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 12 for calling a global function with example usage: test_trainer_datamodule_hook_system(tmpdir) without return types