code: def test_polling(self):
      datasets = {"d1": d1, "d2": d2, "d3": d3}
      dl = MixDataLoader(
          datasets=datasets,
          mode="polling",
          collate_fn="auto",
          batch_size=18,
      )
      for idx, batch in enumerate(dl):
          if idx == 0 or idx == 3:
              assert batch["x"][:3].tolist() == [
                  [1, 2, 0, 0],
                  [2, 3, 4, 0],
                  [4, 5, 6, 7],
              ]
              assert batch["x"].shape[1] == 4
          elif idx == 1 or idx == 4:
              # d2
              assert batch["x"][:3].tolist() == [
                  [101, 201, 0],
                  [201, 301, 401],
                  [100, 0, 0],
              ]
              assert batch["x"].shape[1] == 3
          elif idx == 2 or 4 < idx <= 20:
              assert batch["x"][:3].tolist() == [
                  [1000, 2000, 0, 0],
                  [0, 0, 0, 0],
                  [2000, 3000, 4000, 5000],
              ]
              assert batch["x"].shape[1] == 4
          if idx > 20:
              raise ValueError(f"out of range")
          _test_pad_val(batch["x"], val=0)
  
      # collate_fn = Callable
      def collate_batch(batch):
          new_batch = {"x": [], "y": []}
          for ins in batch:
              new_batch["x"].append(ins["x"])
              new_batch["y"].append(ins["y"])
          return new_batch
  
      dl1 = MixDataLoader(
          datasets=datasets,
          mode="polling",
          collate_fn=collate_batch,
          batch_size=18,
      )
      for idx, batch in enumerate(dl1):
          if idx == 0 or idx == 3:
              assert batch["x"][:3] == [[1, 2], [2, 3, 4], [4, 5, 6, 7]]
          elif idx == 1 or idx == 4:
              # d2
              assert batch["x"][:3] == [
                  [101, 201],
                  [201, 301, 401],
                  [100],
              ]
          elif idx == 2 or 4 < idx <= 20:
              assert batch["x"][:3] == [
                  [1000, 2000],
                  [0],
                  [2000, 3000, 4000, 5000],
              ]
          if idx > 20:
              raise ValueError(f"out of range")
  
      collate_fns = {
          "d1": Collator(backend="auto").set_pad("x", -1),
          "d2": Collator(backend="auto").set_pad("x", -2),
          "d3": Collator(backend="auto").set_pad("x", -3),
      }
      dl1 = MixDataLoader(
          datasets=datasets,
          mode="polling",
          collate_fn=collate_fns,
          batch_size=18,
      )
      for idx, batch in enumerate(dl1):
          if idx == 0 or idx == 3:
              assert _test_pad_val(batch["x"], val=-1)
              assert batch["x"][:3].tolist() == [
                  [1, 2, -1, -1],
                  [2, 3, 4, -1],
                  [4, 5, 6, 7],
              ]
              assert batch["x"].shape[1] == 4
          elif idx == 1 or idx == 4:
              # d2
              assert _test_pad_val(batch["x"], val=-2)
              assert batch["x"][:3].tolist() == [
                  [101, 201, -2],
                  [201, 301, 401],
                  [100, -2, -2],
              ]
              assert batch["x"].shape[1] == 3
          elif idx == 2 or 4 < idx <= 20:
              assert _test_pad_val(batch["x"], val=-3)
              assert batch["x"][:3].tolist() == [
                  [1000, 2000, -3, -3],
                  [0, -3, -3, -3],
                  [2000, 3000, 4000, 5000],
              ]
              assert batch["x"].shape[1] == 4
          if idx > 20:
              raise ValueError(f"out of range")
  
      # sampler 为 str
      dl2 = MixDataLoader(
          datasets=datasets,
          mode="polling",
          sampler="seq",
          batch_size=18,
      )
      dl3 = MixDataLoader(
          datasets=datasets,
          mode="polling",
          sampler="rand",
          batch_size=18,
      )
      for idx, batch in enumerate(dl2):
          if idx == 0 or idx == 3:
              assert batch["x"][:3].tolist() == [
                  [1, 2, 0, 0],
                  [2, 3, 4, 0],
                  [4, 5, 6, 7],
              ]
              assert batch["x"].shape[1] == 4
          elif idx == 1 or idx == 4:
              # d2
              assert batch["x"][:3].tolist() == [
                  [101, 201, 0],
                  [201, 301, 401],
                  [100, 0, 0],
              ]
              assert batch["x"].shape[1] == 3
          elif idx == 2 or 4 < idx <= 20:
              assert batch["x"][:3].tolist() == [
                  [1000, 2000, 0, 0],
                  [0, 0, 0, 0],
                  [2000, 3000, 4000, 5000],
              ]
              assert batch["x"].shape[1] == 4
          if idx > 20:
              raise ValueError(f"out of range")
          _test_pad_val(batch["x"], val=0)
      for idx, batch in enumerate(dl3):
          if idx == 0 or idx == 3:
              assert batch["x"].shape[1] == 4
          elif idx == 1 or idx == 4:
              # d2
              assert batch["x"].shape[1] == 3
          elif idx == 2 or 4 < idx <= 20:
              assert batch["x"].shape[1] == 4
          if idx > 20:
              raise ValueError(f"out of range")
          _test_pad_val(batch["x"], val=0)
      # sampler 为 Dict
      samplers = {
          "d1": SequentialSampler(d1),
          "d2": SequentialSampler(d2),
          "d3": RandomSampler(d3),
      }
      dl4 = MixDataLoader(
          datasets=datasets,
          mode="polling",
          sampler=samplers,
          batch_size=18,
      )
      for idx, batch in enumerate(dl4):
          if idx == 0 or idx == 3:
              assert batch["x"][:3].tolist() == [
                  [1, 2, 0, 0],
                  [2, 3, 4, 0],
                  [4, 5, 6, 7],
              ]
              assert batch["x"].shape[1] == 4
          elif idx == 1 or idx == 4:
              # d2
              assert batch["x"][:3].tolist() == [
                  [101, 201, 0],
                  [201, 301, 401],
                  [100, 0, 0],
              ]
              assert batch["x"].shape[1] == 3
          elif idx == 2 or 4 < idx <= 20:
              assert batch["x"].shape[1] == 4
          if idx > 20:
              raise ValueError(f"out of range")
          _test_pad_val(batch["x"], val=0)
  
      # ds_ratio 为 'truncate_to_least'
      dl5 = MixDataLoader(
          datasets=datasets,
          mode="polling",
          ds_ratio="truncate_to_least",
          batch_size=18,
      )
      for idx, batch in enumerate(dl5):
          if idx == 0 or idx == 3:
              assert batch["x"][:3].tolist() == [
                  [1, 2, 0, 0],
                  [2, 3, 4, 0],
                  [4, 5, 6, 7],
              ]
              assert batch["x"].shape[1] == 4
          elif idx == 1 or idx == 4:
              # d2
              assert batch["x"][:3].tolist() == [
                  [101, 201, 0],
                  [201, 301, 401],
                  [100, 0, 0],
              ]
              assert batch["x"].shape[1] == 3
          elif idx == 2 or idx == 5:
              assert batch["x"][:3].tolist() == [
                  [1000, 2000, 0, 0],
                  [0, 0, 0, 0],
                  [2000, 3000, 4000, 5000],
              ]
              assert batch["x"].shape[1] == 4
          if idx > 5:
              raise ValueError(f"out of range")
          _test_pad_val(batch["x"], val=0)
  
      # ds_ratio 为 'pad_to_most'
      dl6 = MixDataLoader(
          datasets=datasets,
          mode="polling",
          ds_ratio="pad_to_most",
          batch_size=18,
      )
      for idx, batch in enumerate(dl6):
          if idx % 3 == 0:
              # d1
              assert batch["x"][:3].tolist() == [
                  [1, 2, 0, 0],
                  [2, 3, 4, 0],
                  [4, 5, 6, 7],
              ]
              assert batch["x"].shape[1] == 4
          if idx % 3 == 1:
              # d2
              assert batch["x"][:3].tolist() == [
                  [101, 201, 0],
                  [201, 301, 401],
                  [100, 0, 0],
              ]
              assert batch["x"].shape[1] == 3
          if idx % 3 == 2:
              # d3
              assert batch["x"][:3].tolist() == [
                  [1000, 2000, 0, 0],
                  [0, 0, 0, 0],
                  [2000, 3000, 4000, 5000],
              ]
              assert batch["x"].shape[1] == 4
          if idx >= 51:
              raise ValueError(f"out of range")
          _test_pad_val(batch["x"], val=0)
  
      # ds_ratio 为 Dict[str, float]
      ds_ratio = {"d1": 1.0, "d2": 2.0, "d3": 2.0}
      dl7 = MixDataLoader(
          datasets=datasets,
          mode="polling",
          ds_ratio=ds_ratio,
          batch_size=18,
      )
      for idx, batch in enumerate(dl7):
          if idx == 0 or idx == 3:
              assert batch["x"][:3].tolist() == [
                  [1, 2, 0, 0],
                  [2, 3, 4, 0],
                  [4, 5, 6, 7],
              ]
              assert batch["x"].shape[1] == 4
          elif idx == 1 or idx == 4 or idx == 6 or idx == 8:
              # d2
              assert batch["x"][:3].tolist() == [
                  [101, 201, 0],
                  [201, 301, 401],
                  [100, 0, 0],
              ]
              assert batch["x"].shape[1] == 3
          elif idx == 2 or idx == 5 or idx == 7 or idx > 8:
              assert batch["x"][:3].tolist() == [
                  [1000, 2000, 0, 0],
                  [0, 0, 0, 0],
                  [2000, 3000, 4000, 5000],
              ]
              assert batch["x"].shape[1] == 4
          if idx > 39:
              raise ValueError(f"out of range")
          _test_pad_val(batch["x"], val=0)
  
      ds_ratio = {"d1": 0.1, "d2": 0.6, "d3": 1.0}
      dl8 = MixDataLoader(
          datasets=datasets,
          mode="polling",
          ds_ratio=ds_ratio,
          batch_size=18,
      )
      for idx, batch in enumerate(dl8):
          if idx == 0:
              assert batch["x"][:3].tolist() == [
                  [1, 2, 0, 0],
                  [2, 3, 4, 0],
                  [4, 5, 6, 7],
              ]
              assert batch["x"].shape[1] == 4
          elif idx == 1:
              # d2
              assert batch["x"][:3].tolist() == [
                  [101, 201, 0],
                  [201, 301, 401],
                  [100, 0, 0],
              ]
              assert batch["x"].shape[1] == 3
          elif idx > 1:
              assert batch["x"][:3].tolist() == [
                  [1000, 2000, 0, 0],
                  [0, 0, 0, 0],
                  [2000, 3000, 4000, 5000],
              ]
              assert batch["x"].shape[1] == 4
  
          if idx > 18:
              raise ValueError(f"out of range")
          _test_pad_val(batch["x"], val=0)
  
file_path: fastNLP/tests/core/dataloaders/torch_dataloader/test_mixdataloader.py
imports: import pytest
  from typing import Mapping
  from fastNLP.core.dataloaders import MixDataLoader
  from fastNLP import DataSet
  from fastNLP.core.collators import Collator
  from fastNLP.envs.imports import _NEED_IMPORT_TORCH
label_desc: Use image node_id 3 for calling the TestMixDataLoader obj's underlying member method code with example usage: obj.test_polling() and returns: new_batch