class_docstr: A subclass of :class:`~allennlp.common.testing.test_case.AllenNlpTestCase`
  with added methods for testing :class:`~allennlp.models.model.Model` subclasses.
class_docstr_tok: ["A","subclass","of",":","class",":","`","~allennlp.common.testing.test_case.AllenNlpTestCase","`","with","added","methods","for","testing",":","class",":","`","~allennlp.models.model.Model","`","subclasses","."]
code: def assert_fields_equal(self, field1, field2, name, tolerance=1e-6):
      if isinstance(field1, torch.Tensor):
          assert_allclose(
              field1.detach().cpu().numpy(),
              field2.detach().cpu().numpy(),
              rtol=tolerance,
              err_msg=name,
          )
      elif isinstance(field1, dict):
          assert list(field1.keys()) == list(field2.keys())
          for key in field1:
              self.assert_fields_equal(
                  field1[key],
                  field2[key],
                  tolerance=tolerance,
                  name=name + "." + unicode(key),
              )
      elif isinstance(field1, (list, tuple)):
          assert len(field1) == len(field2)
          for i, (subfield1, subfield2) in enumerate(
              izip(field1, field2)
          ):
              self.assert_fields_equal(
                  subfield1,
                  subfield2,
                  tolerance=tolerance,
                  name=name + "[{i}]",
              )
      elif isinstance(field1, (float, int)):
          assert_allclose(
              [field1], [field2], rtol=tolerance, err_msg=name
          )
      else:
          assert field1 == field2
  
file_path: magnitude/pymagnitude/third_party/allennlp/common/testing/model_test_case.py
imports: from __future__ import division
  from __future__ import absolute_import
  from __future__ import print_function
  import copy
  from numpy.testing import assert_allclose
  import torch
  from allennlp.commands.train import train_model_from_file
  from allennlp.common import Params
  from allennlp.common.testing.test_case import AllenNlpTestCase
  from allennlp.data import DataIterator, DatasetReader, Vocabulary
  from allennlp.data.dataset import Batch
  from allennlp.models import Model, load_archive
label_desc: Use image node_id 3 for calling the ModelTestCase obj's underlying member method code with example usage: obj.assert_fields_equal(field1, field2, name, tolerance) without return types