code: def test_bucket_batch_sampler(self):
      bucket_size_multiplier = 2
      sampler = range(len(train_samples))
      sampler = BucketBatchSampler(
          sampler,
          data=train_samples,
          batch_size=7,
          drop_last=True,
          sort_key=lambda x: len(x["text"]),
          bucket_size_multiplier=bucket_size_multiplier,
      )
  
      # check if the samples are sorted by text lenght whuile bucketing
      min_text_len_in_bucket = 0
      bucket_items = []
      for batch_idx, batch in enumerate(list(sampler)):
          if (batch_idx + 1) % bucket_size_multiplier == 0:
              for bucket_item in bucket_items:
                  self.assertLessEqual(
                      min_text_len_in_bucket,
                      len(train_samples[bucket_item]["text"]),
                  )
                  min_text_len_in_bucket = len(
                      train_samples[bucket_item]["text"]
                  )
              min_text_len_in_bucket = 0
              bucket_items = []
          else:
              bucket_items += batch
  
      # check sampler length
      self.assertEqual(len(sampler), len(train_samples) // 7)
  
file_path: TTS/tests/data_tests/test_samplers.py
imports: import functools
  import random
  import unittest
  import torch
  from TTS.config.shared_configs import BaseDatasetConfig
  from TTS.tts.datasets import load_tts_samples
  from TTS.tts.utils.data import get_length_balancer_weights
  from TTS.tts.utils.languages import get_language_balancer_weights
  from TTS.tts.utils.speakers import get_speaker_balancer_weights
  from TTS.utils.samplers import BucketBatchSampler, PerfectBatchSampler
label_desc: Use image node_id 7 for calling the TestSamplers obj's underlying member method code with example usage: obj.test_bucket_batch_sampler() without return types