class_docstr: Tests tfrecord data class.
      
class_docstr_tok: ["Tests","tfrecord","data","class","."]
code: def setUp(self):
      tf.test.TestCase.setUp(self)
  
      # Create test data
      # pylint: disable=no-member
      self._test_dir = tempfile.mkdtemp()
  
      cat_in_snow = tf.keras.utils.get_file(
          os.path.join(self._test_dir, "cat_0.jpg"),
          "https://storage.googleapis.com/download.tensorflow.org/"
          "example_images/320px-Felis_catus-cat_on_snow.jpg",
      )
      williamsburg_bridge = tf.keras.utils.get_file(
          os.path.join(self._test_dir, "bridge_0.jpg"),
          "https://storage.googleapis.com/download.tensorflow.org/"
          "example_images/194px-New_East_River_Bridge_from_Brooklyn_"
          "det.4a09796u.jpg",
      )
  
      def _bytes_feature(value=None):
          """Returns a bytes_list from a string / byte."""
          # pylint: disable=undefined-loop-variable
          value = tf.compat.as_bytes(value, encoding="utf-8")
          return tf.train.Feature(
              bytes_list=tf.train.BytesList(value=[value])
          )
  
      def _int64_feature(value=None):
          """Returns an int64_list from a bool / enum / int / uint."""
          return tf.train.Feature(
              int64_list=tf.train.Int64List(value=[value])
          )
  
      _feature_original_types = {
          "height": ["tf.int64", "FixedLenFeature"],
          "width": ["tf.int64", "FixedLenFeature"],
          "label": ["tf.int64", "FixedLenFeature"],
          "shape": [tf.int64, "VarLenFeature"],
          "image_raw": ["tf.string", "FixedLenFeature"],
          "variable1": [tf.string, "FixedLenFeature"],
          "variable2": ["tf.int64", "FixedLenFeature"],
      }
      self._feature_convert_types = {
          "variable1": "tf.float32",
          "variable2": "tf.string",
      }
      _image_options = {}
      self._unconvert_features = ["height", "width", "label"]
  
      def _image_example(image_string, image_shape, label):
          """Create data example with image"""
          feature = {
              "height": _int64_feature(image_shape[0]),
              "width": _int64_feature(image_shape[1]),
              "shape": tf.train.Feature(
                  int64_list=tf.train.Int64List(value=list(image_shape))
              ),
              "label": _int64_feature(label),
              "image_raw": _bytes_feature(image_string),
              "variable1": _bytes_feature("1234567890"),
              "variable2": _int64_feature(9876543210),
          }
          return tf.train.Example(
              features=tf.train.Features(feature=feature)
          )
  
      self._dataset_valid = {
          "height": [],
          "width": [],
          "shape": [],
          "label": [],
          "image_raw": [],
          "variable1": [],
          "variable2": [],
      }
      _toy_image_labels_valid = {
          cat_in_snow: 0,
          williamsburg_bridge: 1,
      }
      _toy_image_shapes = {
          cat_in_snow: (213, 320, 3),
          williamsburg_bridge: (239, 194),
      }
      _tfrecord_filepath = os.path.join(self._test_dir, "test.tfrecord")
      # Prepare Validation data
      with tf.python_io.TFRecordWriter(_tfrecord_filepath) as writer:
          for image_path, label in _toy_image_labels_valid.items():
              with open(image_path, "rb") as fid:
                  image_data = fid.read()
              image_shape = _toy_image_shapes[image_path]
  
              tf_example = _image_example(
                  image_data, image_shape, label
              )
              writer.write(tf_example.SerializeToString())
  
              # _construct_dataset_valid("", shape, label)
              single_data = {
                  "height": image_shape[0],
                  "width": image_shape[1],
                  "shape": image_shape,
                  "label": label,
                  "image_raw": image_data,
                  "variable1": "1234567890",
                  "variable2": int(9876543210),
              }
              for key, value in single_data.items():
                  self._dataset_valid[key].append(value)
  
      self._hparams = {
          "num_epochs": 1,
          "batch_size": 1,
          "shuffle": False,
          "dataset": {
              "files": _tfrecord_filepath,
              "feature_original_types": _feature_original_types,
              "feature_convert_types": self._feature_convert_types,
              "image_options": [_image_options],
          },
      }
  
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 1 for calling the TFRecordDataTest obj's underlying member method code with example usage: obj.setUp() and returns: tf, tf, tf