code: def test_num_dataloader_batches(tmpdir):
      """Tests that the correct number of batches are allocated."""
      # when we have fewer batches in the dataloader we should use those instead of the limit
      model = BoringModel()
      trainer = Trainer(
          limit_val_batches=100,
          limit_train_batches=100,
          max_epochs=1,
          default_root_dir=tmpdir,
      )
      trainer.fit(model)
  
      assert len(model.train_dataloader()) == 64
      assert len(model.val_dataloader()) == 64
      assert isinstance(trainer.num_val_batches, list)
      assert trainer.num_val_batches[0] == 64
      assert trainer.num_training_batches == 64
  
      # when we have more batches in the dataloader we should limit them
      model = BoringModel()
      trainer = Trainer(
          limit_val_batches=7,
          limit_train_batches=7,
          max_epochs=1,
          default_root_dir=tmpdir,
      )
      trainer.fit(model)
  
      assert len(model.train_dataloader()) == 64
      assert len(model.val_dataloader()) == 64
      assert isinstance(trainer.num_val_batches, list)
      assert trainer.num_val_batches[0] == 7
      assert trainer.num_training_batches == 7
  
file_path: pytorch-lightning/tests/tests_pytorch/trainer/flags/test_limit_batches.py
imports: import logging
  import pytest
  from lightning.pytorch import Trainer
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.trainer.states import TrainerFn
label_desc: Use image node_id 1 for calling a global function with example usage: test_num_dataloader_batches(tmpdir) without return types