code: def test_bucket_iterator_maximum_samples_per_batch(self):
      iterator = BucketIterator(
          batch_size=3,
          padding_noise=0,
          sorting_keys=[("text", "num_tokens")],
          maximum_samples_per_batch=["num_tokens", 9],
      )
      batches = list(
          iterator._create_batches(self.instances, shuffle=False)
      )
  
      # ensure all instances are in a batch
      grouped_instances = [batch.instances for batch in batches]
      num_instances = sum(len(group) for group in grouped_instances)
      assert num_instances == len(self.instances)
  
      # ensure all batches are sufficiently small
      for batch in batches:
          batch_sequence_length = max(
              [
                  instance.get_padding_lengths()["text"]["num_tokens"]
                  for instance in batch.instances
              ]
          )
          assert batch_sequence_length * len(batch.instances) <= 9
  
file_path: magnitude/pymagnitude/third_party/allennlp/tests/data/iterators/bucket_iterator_test.py
imports: from __future__ import with_statement
  from __future__ import absolute_import
  import pytest
  from allennlp.common import Params
  from allennlp.common.checks import ConfigurationError
  from allennlp.data.iterators import BucketIterator
  from allennlp.tests.data.iterators.basic_iterator_test import IteratorTest
label_desc: Use image node_id 5 for calling the TestBucketIterator obj's underlying member method code with example usage: obj.test_bucket_iterator_maximum_samples_per_batch() without return types