code: def test_drop_last_works(self):
      sampler = BucketBatchSampler(
          batch_size=2,
          padding_noise=0,
          sorting_keys=["text"],
          drop_last=True,
      )
  
      # We use a custom collate_fn for testing, which doesn't actually create tensors,
      # just the allennlp Batches.
      def collate_fn(x, **kwargs):
          return Batch(x)
  
      data_loader = MultiProcessDataLoader(
          self.get_mock_reader(),
          "fake_path",
          batch_sampler=sampler,
      )
      data_loader.collate_fn = collate_fn
      data_loader.index_with(self.vocab)
      batches = [batch for batch in iter(data_loader)]
      stats = self.get_batches_stats(batches)
  
      # all batches have length batch_size
      assert all(batch_len == 2 for batch_len in stats["batch_lengths"])
  
      # we should have lost one instance by skipping the last batch
      assert stats["total_instances"] == len(self.instances) - 1
  
file_path: allennlp/tests/data/samplers/bucket_batch_sampler_test.py
imports: from allennlp.common import Params
  from allennlp.data import Instance, Token, Batch
  from allennlp.data.fields import TextField
  from allennlp.data.samplers import BucketBatchSampler
  from allennlp.data.data_loaders import MultiProcessDataLoader
  from .sampler_test import SamplerTest
label_desc: Use image node_id 5 for calling the TestBucketSampler obj's underlying member method code with example usage: obj.test_drop_last_works() and returns: Batch