code: def test_create_batches_groups_correctly(self):
      iterator = BucketIterator(
          batch_size=2,
          padding_noise=0,
          sorting_keys=[("text", "num_tokens")],
      )
      batches = list(
          iterator._create_batches(self.instances, shuffle=False)
      )
      grouped_instances = [batch.instances for batch in batches]
      assert grouped_instances == [
          [self.instances[4], self.instances[2]],
          [self.instances[0], self.instances[1]],
          [self.instances[3]],
      ]
  
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 1 for calling the TestBucketIterator obj's underlying member method code with example usage: obj.test_create_batches_groups_correctly() without return types