code: def test_named_tuple():
      a = _TestNamedTuple([1, 2, 3, 4], 0)
      b = _TestNamedTuple([5, 7], 1)
      c = _TestNamedTuple([1, 2, 3, 4, 5, 6, 7], 0)
      with pytest.raises(ValueError):
          wrong_batchify_fn = batchify.NamedTuple(
              _TestNamedTuple,
              {"data0": batchify.Pad(), "label": batchify.Stack()},
          )
      with pytest.raises(ValueError):
          wrong_batchify_fn = batchify.NamedTuple(
              _TestNamedTuple,
              [batchify.Pad(), batchify.Stack(), batchify.Stack()],
          )
      with pytest.raises(ValueError):
          wrong_batchify_fn = batchify.NamedTuple(
              _TestNamedTuple, (batchify.Pad(),)
          )
      with pytest.raises(ValueError):
          wrong_batchify_fn = batchify.NamedTuple(
              _TestNamedTuple, [1, 2]
          )
      for batchify_fn in [
          batchify.NamedTuple(
              _TestNamedTuple,
              {"data": batchify.Pad(), "label": batchify.Stack()},
          ),
          batchify.NamedTuple(
              _TestNamedTuple, [batchify.Pad(), batchify.Stack()]
          ),
          batchify.NamedTuple(
              _TestNamedTuple, (batchify.Pad(), batchify.Stack())
          ),
      ]:
          sample = batchify_fn([a, b, c])
          gt_data = batchify.Pad()([a[0], b[0], c[0]])
          gt_label = batchify.Stack()([a[1], b[1], c[1]])
          assert isinstance(sample, _TestNamedTuple)
          assert_allclose(sample.data.asnumpy(), gt_data.asnumpy())
          assert_allclose(sample.label.asnumpy(), gt_label.asnumpy())
          with pytest.raises(ValueError):
              batchify_fn([1, 2, 3])
  
file_path: gluon-nlp/tests/test_data_batchify.py
imports: import numpy
  from numpy.testing import assert_allclose
  from collections import namedtuple
  import mxnet
  from gluonnlp.data import batchify
  import pytest
label_desc: Use image node_id 2 for calling a global function with example usage: test_named_tuple() without return types