code: def test_flush_and_close(self):
      logdir = self.get_temp_dir()
      output = output_lib.DirectoryOutput(logdir)
      emit_scalar = lambda step: output.emit_scalar(
          plugin_name="plugin",
          tag="tag",
          data=np.float32(0),
          step=np.int64(step),
          wall_time=0.0,
          tag_metadata=b"meta",
          description="desc",
      )
      emit_scalar(1)
      # We can't assert on the contents of the event file prior to calling
      # flush() since it's nondeterministic depending on filesystem impl.
      # See #4582 discussion for details.
      output.flush()
      # Expect file version and first scalar event.
      events = _test_util.read_tfevents(logdir)
      self.assertLen(events, 2)
      self.assertEqual(events[0].file_version, "brain.Event:2")
      self.assertEqual(events[1].step, 1)
      emit_scalar(2)
      output.close()
      # Now we should see both scalar events.
      events = _test_util.read_tfevents(logdir)
      self.assertLen(events, 3)
      self.assertEqual(events[2].step, 2)
  
file_path: tensorboard/tensorboard/summary/_output_test.py
imports: import numpy
  from tensorboard.compat.proto import summary_pb2
  from tensorboard.compat.proto import types_pb2
  from tensorboard.summary import _output
  from tensorboard.summary import _test_util
  from tensorboard.util import tensor_util
  from tensorboard import test
label_desc: Use image node_id 2 for calling the DirectoryOutputTest obj's underlying member method code with example usage: obj.test_flush_and_close() without return types