# Path: tf_slim/summaries.py
# def _get_summary_name(tensor, name=None, prefix=None, postfix=None):
# def add_histogram_summary(tensor, name=None, prefix=None):
# def add_image_summary(tensor, name=None, prefix=None, print_summary=False):
# def add_scalar_summary(tensor, name=None, prefix=None, print_summary=False):
# def add_zero_fraction_summary(tensor, name=None, prefix=None,
#                               print_summary=False):
# def add_histogram_summaries(tensors, prefix=None):
# def add_image_summaries(tensors, prefix=None):
# def add_scalar_summaries(tensors, prefix=None, print_summary=False):
# def add_zero_fraction_summaries(tensors, prefix=None):


import glob
import os
import tempfile
import tensorflow.compat.v1 as tf
from tf_slim import summaries
from tensorflow.python.framework import ops
from tensorflow.python.ops import array_ops
from tensorflow.python.platform import test
from tensorflow.python.summary import summary
from tensorflow.python.summary import summary_iterator


class SummariesTest(test.TestCase):

  def assert_scalar_summary(self, output_dir, names_to_values):
    """Asserts that the given output directory contains written summaries.

    Args:
      output_dir: The output directory in which to look for even tfiles.
      names_to_values: A dictionary of summary names to values.
    """
    # The events file may have additional entries, e.g. the event version
    # stamp, so have to parse things a bit.
    output_filepath = glob.glob(os.path.join(output_dir, '*'))
    self.assertEqual(len(output_filepath), 1)

    events = summary_iterator.summary_iterator(output_filepath[0])
    summaries_list = [e.summary for e in events if e.summary.value]
    values = []
    for item in summaries_list:
      for value in item.value:
        values.append(value)
    saved_results = {v.tag: v.simple_value for v in values}
    for name in names_to_values:
      self.assertAlmostEqual(names_to_values[name], saved_results[name])

  def testScalarSummaryIsPartOfCollectionWithNoPrint(self):
    tensor = array_ops.ones([]) * 3
    name = 'my_score'
    prefix = 'eval'

# Path: tf_slim/summaries.py
# def _get_summary_name(tensor, name=None, prefix=None, postfix=None):
# def add_histogram_summary(tensor, name=None, prefix=None):
# def add_image_summary(tensor, name=None, prefix=None, print_summary=False):
# def add_scalar_summary(tensor, name=None, prefix=None, print_summary=False):
# def add_zero_fraction_summary(tensor, name=None, prefix=None,
#                               print_summary=False):
# def add_histogram_summaries(tensors, prefix=None):
# def add_image_summaries(tensors, prefix=None):
# def add_scalar_summaries(tensors, prefix=None, print_summary=False):
# def add_zero_fraction_summaries(tensors, prefix=None):


# Path: tf_slim/summaries_test.py
import glob
import os
import tempfile
import tensorflow.compat.v1 as tf
from tf_slim import summaries
from tensorflow.python.framework import ops
from tensorflow.python.ops import array_ops
from tensorflow.python.platform import test
from tensorflow.python.summary import summary
from tensorflow.python.summary import summary_iterator



class SummariesTest(test.TestCase):

  def assert_scalar_summary(self, output_dir, names_to_values):
    """Asserts that the given output directory contains written summaries.

    Args:
      output_dir: The output directory in which to look for even tfiles.
      names_to_values: A dictionary of summary names to values.
    """
    # The events file may have additional entries, e.g. the event version
    # stamp, so have to parse things a bit.
    output_filepath = glob.glob(os.path.join(output_dir, '*'))
    self.assertEqual(len(output_filepath), 1)

    events = summary_iterator.summary_iterator(output_filepath[0])
    summaries_list = [e.summary for e in events if e.summary.value]
    values = []
    for item in summaries_list:
      for value in item.value:
        values.append(value)
    saved_results = {v.tag: v.simple_value for v in values}
    for name in names_to_values:
      self.assertAlmostEqual(names_to_values[name], saved_results[name])

  def testScalarSummaryIsPartOfCollectionWithNoPrint(self):
    tensor = array_ops.ones([]) * 3
    name = 'my_score'
    prefix = 'eval'

    op = summaries.add_scalar_summary(tensor, name, prefix, print_summary=False)