# Path: sockeye/config.py
# class Config(yaml.YAMLObject, metaclass=TaggedYamlObjectMetaclass):
#     """
#     Base configuration object YAML (de-)serialization.
#     Actual Configuration should subclass this object.
#     """
#     yaml_loader = SafeLoaderWithTuple  # type: ignore
# 
#     def save(self, fname: str):
#         """
#         Saves this Config to a file called fname.
# 
#         :param fname: Name of file to store this Config in.
#         """
#         obj = copy.deepcopy(self)
#         with open(fname, 'w') as out:
#             yaml.dump(obj, out, default_flow_style=False)
# 
#     @staticmethod
#     def load(fname: str) -> 'Config':
#         """
#         Returns a Config object loaded from a file.
# 
#         :param fname: Name of file to load the Config from.
#         :return: Configuration.
#         """
#         with open(fname) as inp:
#             obj = yaml.load(inp, Loader=SafeLoaderWithTuple)  # type: ignore
#             return obj
# 
#     def copy(self, **kwargs):
#         """
#         Create a copy of the config object, optionally modifying some of the attributes.
#         For example `nn_config.copy(num_hidden=512)` will create a copy of `nn_config` where the attribute `num_hidden`
#         will be set to the new value of num_hidden.
# 
#         :param kwargs:
#         :return: A deep copy of the config object.
#         """
#         copy_obj = copy.deepcopy(self)
#         for name, value in kwargs.items():
#             object.__setattr__(copy_obj, name, value)
#         return copy_obj
# 
#     def disable_dropout(self):
#         """
#         Sets the value of all float-valued attributes in this config (or any of its children) that contain 'dropout'
#         in their name to 0.0.
#         """
#         for attr, val in self.__dict__.items():
#             if isinstance(val, Config):
#                 val.disable_dropout()
#             elif 'dropout' in attr and isinstance(val, float):
#                 logger.debug("Setting %s to 0.0", attr)
#                 setattr(self, attr, 0.0)


import tempfile
import os
from dataclasses import dataclass
from typing import Any, Optional
from sockeye.config import Config
    c1_other = ConfigTest(param=1)
    c2 = ConfigTest(param=2)

    c_nested = ConfigTest(param=1, config=c1)
    c_nested_other = ConfigTest(param=1, config=c1_other)
    c_nested_c2 = ConfigTest(param=1, config=c2)

    assert c1 != "OTHER_TYPE"
    assert c1 != basic_c
    assert c1 == c1_other
    assert c1 != c2
    assert c_nested == c_nested_other
    assert c_nested != c_nested_c2


def test_config_serialization():
    c1 = ConfigTest(param=1, config=ConfigTest(param=2))
    expected_serialization = """!ConfigTest
config: !ConfigTest
  config: null
  param: 2
param: 1
"""
    with tempfile.TemporaryDirectory() as tmp_dir:
        fname = os.path.join(tmp_dir, "config")
        c1.save(fname)
        assert os.path.exists(fname)
        with open(fname) as f:
            assert f.read() == expected_serialization


# Path: sockeye/config.py
# class Config(yaml.YAMLObject, metaclass=TaggedYamlObjectMetaclass):
#     """
#     Base configuration object YAML (de-)serialization.
#     Actual Configuration should subclass this object.
#     """
#     yaml_loader = SafeLoaderWithTuple  # type: ignore
# 
#     def save(self, fname: str):
#         """
#         Saves this Config to a file called fname.
# 
#         :param fname: Name of file to store this Config in.
#         """
#         obj = copy.deepcopy(self)
#         with open(fname, 'w') as out:
#             yaml.dump(obj, out, default_flow_style=False)
# 
#     @staticmethod
#     def load(fname: str) -> 'Config':
#         """
#         Returns a Config object loaded from a file.
# 
#         :param fname: Name of file to load the Config from.
#         :return: Configuration.
#         """
#         with open(fname) as inp:
#             obj = yaml.load(inp, Loader=SafeLoaderWithTuple)  # type: ignore
#             return obj
# 
#     def copy(self, **kwargs):
#         """
#         Create a copy of the config object, optionally modifying some of the attributes.
#         For example `nn_config.copy(num_hidden=512)` will create a copy of `nn_config` where the attribute `num_hidden`
#         will be set to the new value of num_hidden.
# 
#         :param kwargs:
#         :return: A deep copy of the config object.
#         """
#         copy_obj = copy.deepcopy(self)
#         for name, value in kwargs.items():
#             object.__setattr__(copy_obj, name, value)
#         return copy_obj
# 
#     def disable_dropout(self):
#         """
#         Sets the value of all float-valued attributes in this config (or any of its children) that contain 'dropout'
#         in their name to 0.0.
#         """
#         for attr, val in self.__dict__.items():
#             if isinstance(val, Config):
#                 val.disable_dropout()
#             elif 'dropout' in attr and isinstance(val, float):
#                 logger.debug("Setting %s to 0.0", attr)
#                 setattr(self, attr, 0.0)


# Path: test/unit/test_config.py
import tempfile
import os
from dataclasses import dataclass
from typing import Any, Optional
from sockeye.config import Config

    c1_other = ConfigTest(param=1)
    c2 = ConfigTest(param=2)

    c_nested = ConfigTest(param=1, config=c1)
    c_nested_other = ConfigTest(param=1, config=c1_other)
    c_nested_c2 = ConfigTest(param=1, config=c2)

    assert c1 != "OTHER_TYPE"
    assert c1 != basic_c
    assert c1 == c1_other
    assert c1 != c2
    assert c_nested == c_nested_other
    assert c_nested != c_nested_c2


def test_config_serialization():
    c1 = ConfigTest(param=1, config=ConfigTest(param=2))
    expected_serialization = """!ConfigTest
config: !ConfigTest
  config: null
  param: 2
param: 1
"""
    with tempfile.TemporaryDirectory() as tmp_dir:
        fname = os.path.join(tmp_dir, "config")
        c1.save(fname)
        assert os.path.exists(fname)
        with open(fname) as f:
            assert f.read() == expected_serialization


        c2 = Config.load(fname)