code: def test_index_batch_sampler():
      """Test `IndexBatchSampler` properly extracts indices."""
      dataset = range(15)
      sampler = SequentialSampler(dataset)
      batch_sampler = BatchSampler(sampler, 3, False)
      index_batch_sampler = _IndexBatchSamplerWrapper(batch_sampler)
  
      assert batch_sampler.batch_size == index_batch_sampler.batch_size
      assert batch_sampler.drop_last == index_batch_sampler.drop_last
      assert batch_sampler.sampler is sampler
      assert index_batch_sampler.sampler is sampler
      assert (
          list(index_batch_sampler)
          == index_batch_sampler.seen_batch_indices
      )
      assert list(index_batch_sampler) == list(batch_sampler)
  
      assert isinstance(index_batch_sampler, Iterable)
      assert has_len(index_batch_sampler)
  
      iterator = iter(index_batch_sampler)
      assert index_batch_sampler.seen_batch_indices == []
      b0 = next(iterator)
      assert b0 == [0, 1, 2]
      assert index_batch_sampler.seen_batch_indices == [b0]
      b1 = next(iterator)
      assert b1 == [3, 4, 5]
      assert index_batch_sampler.seen_batch_indices == [b0, b1]
  
file_path: pytorch-lightning/tests/tests_pytorch/overrides/test_distributed.py
imports: from typing import Iterable
  import pytest
  import torch
  from lightning.fabric.utilities.data import has_len
  from lightning.pytorch import LightningModule, Trainer, seed_everything
  from lightning.pytorch.overrides.distributed import UnrepeatedDistributedSampler, _IndexBatchSamplerWrapper
  from torch.utils.data import BatchSampler, SequentialSampler
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 3 for calling a global function with example usage: test_index_batch_sampler() without return types