class_docstr: Tests tfrecord data class.
      
class_docstr_tok: ["Tests","tfrecord","data","class","."]
code: def _run_and_test(self, hparams):
      # Construct database
      tfrecord_data = tx.data.TFRecordData(hparams)
      iterator = tfrecord_data.dataset.make_initializable_iterator()
      data_batch = iterator.get_next()
  
      with self.test_session() as sess:
          sess.run(tf.global_variables_initializer())
          sess.run(tf.local_variables_initializer())
          sess.run(tf.tables_initializer())
          sess.run(iterator.initializer)
          i = 0
  
          def _prod(lst):
              res = 1
              for i in lst:
                  res *= i
              return res
  
          while True:
              try:
                  # Run the logics
                  data_batch_ = sess.run(data_batch)
                  self.assertEqual(
                      set(data_batch_.keys()),
                      set(tfrecord_data.list_items()),
                  )
  
                  # Check data consistency
                  for key in self._unconvert_features:
                      value = data_batch_[key][0]
                      self.assertEqual(
                          value, self._dataset_valid[key][i]
                      )
                  self.assertEqual(
                      list(data_batch_["shape"].values),
                      list(self._dataset_valid["shape"][i]),
                  )
  
                  # Check data type conversion
                  for key, item in self._feature_convert_types.items():
                      value = data_batch_[key][0]
                      if item == "tf.string" or item is tf.string:
                          self.assertTrue(isinstance(value, bytes))
                      else:
                          dtype_matched = tx.utils.dtypes.get_tf_dtype(
                              str(value.dtype)
                          ) is tx.utils.dtypes.get_tf_dtype(item)
                          self.assertTrue(dtype_matched)
  
                  # Check image decoding and resize
                  if hparams["dataset"].get("image_options"):
                      image_options = hparams["dataset"].get(
                          "image_options"
                      )
                      if isinstance(image_options, dict):
                          image_options = [image_options]
                      for image_option_feature in image_options:
                          image_key = image_option_feature.get(
                              "image_feature_name"
                          )
                          if image_key is None:
                              continue
                          image_gen = data_batch_[image_key][0]
                          image_valid_shape = self._dataset_valid[
                              "shape"
                          ][i]
                          resize_height = image_option_feature.get(
                              "resize_height"
                          )
                          resize_width = image_option_feature.get(
                              "resize_width"
                          )
                          if resize_height and resize_width:
                              self.assertEqual(
                                  image_gen.shape[0]
                                  * image_gen.shape[1],
                                  resize_height * resize_width,
                              )
                          else:
                              self.assertEqual(
                                  _prod(image_gen.shape),
                                  _prod(image_valid_shape),
                              )
                  i += 1
              except tf.errors.OutOfRangeError:
                  print("Done -- epoch limit reached")
                  break
  
file_path: texar/tests/data/data/tfrecord_data_test.py
imports: import os
  import sys
  import copy
  import shutil
  import tempfile
  import ssl
  import tensorflow
  import texar.tf
label_desc: Use image node_id 3 for calling the TFRecordDataTest obj's underlying member method code with example usage: obj._run_and_test(hparams) and returns: res