# Path: disentanglement_lib/utils/results.py
# def update_result_directory(result_directory,
#                             step_name,
#                             results_dict,
#                             old_result_directory=None):
# def _copy_recursively(path_to_old_dir, path_to_new_dir):
# def copydir(path_to_old_dir, path_to_new_dir):
# def save_gin(config_path):
#   def default(self, obj):
# def save_dict(config_path, dict_with_info):
# def gin_dict(config_path=None):
# def namespaced_dict(base_dict=None, **named_dicts):
# def aggregate_json_results(base_path):
# class Encoder(json.JSONEncoder):


import os
import tensorflow.compat.v1 as tf
import gin.tf
from disentanglement_lib.utils import results

"""Tests for results.py."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


@gin.configurable("test")
def test_fn(value=gin.REQUIRED):
  return value


class ResultsTest(tf.test.TestCase):

  def test_namespaced_dict(self):
    """Tests namespacing functionality."""
    base_dict = {"!": "!!"}
    numbers = {"1": "one"}
    chars = {"a": "A"}
    new_dict = results.namespaced_dict(base_dict, numbers=numbers, chars=chars)
    self.assertDictEqual(new_dict, {
        "!": "!!",
        "numbers.1": "one",
        "chars.a": "A"
    })

  def test_dict_to_txt(self):
    """Tests saving functionality to txt file."""
    output_path = os.path.join(self.get_temp_dir(), "export.csv")
    output_dict = {"1": "one"}

# Path: disentanglement_lib/utils/results.py
# def update_result_directory(result_directory,
#                             step_name,
#                             results_dict,
#                             old_result_directory=None):
# def _copy_recursively(path_to_old_dir, path_to_new_dir):
# def copydir(path_to_old_dir, path_to_new_dir):
# def save_gin(config_path):
#   def default(self, obj):
# def save_dict(config_path, dict_with_info):
# def gin_dict(config_path=None):
# def namespaced_dict(base_dict=None, **named_dicts):
# def aggregate_json_results(base_path):
# class Encoder(json.JSONEncoder):


# Path: disentanglement_lib/utils/results_test.py
import os
import tensorflow.compat.v1 as tf
import gin.tf
from disentanglement_lib.utils import results


"""Tests for results.py."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


@gin.configurable("test")
def test_fn(value=gin.REQUIRED):
  return value


class ResultsTest(tf.test.TestCase):

  def test_namespaced_dict(self):
    """Tests namespacing functionality."""
    base_dict = {"!": "!!"}
    numbers = {"1": "one"}
    chars = {"a": "A"}
    new_dict = results.namespaced_dict(base_dict, numbers=numbers, chars=chars)
    self.assertDictEqual(new_dict, {
        "!": "!!",
        "numbers.1": "one",
        "chars.a": "A"
    })

  def test_dict_to_txt(self):
    """Tests saving functionality to txt file."""
    output_path = os.path.join(self.get_temp_dir(), "export.csv")
    output_dict = {"1": "one"}

    results.save_dict(output_path, output_dict)