docstr: Test accumulator by writing values and then reading them.
docstr_tok: ["Test","accumulator","by","writing","values","and","then","reading","them","."]
code: def testTensorsRealistically(self):
      """Test accumulator by writing values and then reading them."""
  
      def FakeScalarSummary(tag, value):
          value = summary_pb2.Summary.Value(tag=tag, simple_value=value)
          summary = summary_pb2.Summary(value=[value])
          return summary
  
      directory = os.path.join(self.get_temp_dir(), "values_dir")
      if tf.io.gfile.isdir(directory):
          tf.io.gfile.rmtree(directory)
      tf.io.gfile.mkdir(directory)
  
      writer = test_util.FileWriter(directory, max_queue=100)
  
      with tf.Graph().as_default() as graph:
          _ = tf.constant([2.0, 1.0])
          # Add a graph to the summary writer.
          writer.add_graph(graph)
          graph_def = graph.as_graph_def(add_shapes=True)
          meta_graph_def = tf.compat.v1.train.export_meta_graph(
              graph_def=graph_def
          )
          writer.add_meta_graph(meta_graph_def)
  
      run_metadata = config_pb2.RunMetadata()
      device_stats = run_metadata.step_stats.dev_stats.add()
      device_stats.device = "test device"
      writer.add_run_metadata(run_metadata, "test run")
  
      # Write a bunch of events using the writer.
      for i in range(30):
          summ_id = FakeScalarSummary("id", i)
          summ_sq = FakeScalarSummary("sq", i * i)
          writer.add_summary(summ_id, i * 5)
          writer.add_summary(summ_sq, i * 5)
      writer.flush()
  
      # Verify that we can load those events properly
      acc = ea.EventAccumulator(directory)
      acc.Reload()
      self.assertTagsEqual(
          acc.Tags(),
          {
              ea.TENSORS: [
                  graph_metadata.RUN_GRAPH_NAME,
                  "id",
                  "sq",
                  "test run",
              ],
              ea.GRAPH: True,
              ea.META_GRAPH: True,
              ea.RUN_METADATA: [],
          },
      )
      id_events = acc.Tensors("id")
      sq_events = acc.Tensors("sq")
      self.assertEqual(30, len(id_events))
      self.assertEqual(30, len(sq_events))
      for i in range(30):
          self.assertEqual(i * 5, id_events[i].step)
          self.assertEqual(i * 5, sq_events[i].step)
          self.assertEqual(
              i,
              tensor_util.make_ndarray(
                  id_events[i].tensor_proto
              ).item(),
          )
          self.assertEqual(
              i * i,
              tensor_util.make_ndarray(
                  sq_events[i].tensor_proto
              ).item(),
          )
  
      # Write a few more events to test incremental reloading
      for i in range(30, 40):
          summ_id = FakeScalarSummary("id", i)
          summ_sq = FakeScalarSummary("sq", i * i)
          writer.add_summary(summ_id, i * 5)
          writer.add_summary(summ_sq, i * 5)
      writer.flush()
  
      # Verify we can now see all of the data
      acc.Reload()
      id_events = acc.Tensors("id")
      sq_events = acc.Tensors("sq")
      self.assertEqual(40, len(id_events))
      self.assertEqual(40, len(sq_events))
      for i in range(40):
          self.assertEqual(i * 5, id_events[i].step)
          self.assertEqual(i * 5, sq_events[i].step)
          self.assertEqual(
              i,
              tensor_util.make_ndarray(
                  id_events[i].tensor_proto
              ).item(),
          )
          self.assertEqual(
              i * i,
              tensor_util.make_ndarray(
                  sq_events[i].tensor_proto
              ).item(),
          )
  
      expected_graph_def = graph_pb2.GraphDef.FromString(
          graph.as_graph_def(add_shapes=True).SerializeToString()
      )
      self.assertProtoEquals(expected_graph_def, acc.Graph())
      self.assertProtoEquals(
          expected_graph_def,
          graph_pb2.GraphDef.FromString(acc.SerializedGraph()),
      )
  
      expected_meta_graph = meta_graph_pb2.MetaGraphDef.FromString(
          meta_graph_def.SerializeToString()
      )
      self.assertProtoEquals(expected_meta_graph, acc.MetaGraph())
  
imports: import os
  from unittest import mock
  import numpy
  import tensorflow
  from tensorboard import data_compat
  from tensorboard import dataclass_compat
  from tensorboard.backend.event_processing import plugin_event_accumulator
  from tensorboard.compat.proto import config_pb2
  from tensorboard.compat.proto import event_pb2
  from tensorboard.compat.proto import graph_pb2
  from tensorboard.compat.proto import meta_graph_pb2
  from tensorboard.compat.proto import summary_pb2
  from tensorboard.plugins.audio import metadata
  from tensorboard.plugins.audio import summary
  from tensorboard.plugins.graph import metadata
  from tensorboard.plugins.image import metadata
  from tensorboard.plugins.image import summary
  from tensorboard.plugins.scalar import metadata
  from tensorboard.plugins.scalar import summary
  from tensorboard.util import tb_logging
  from tensorboard.util import tensor_util
  from tensorboard.util import test_util
label_desc: Use image node_id 1 for calling the RealisticEventAccumulatorTest obj's underlying member method code with example usage: obj.testTensorsRealistically() and returns: summary