# 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
# Copyright 2017--2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may not
# use this file except in compliance with the License. A copy of the License
# is located at
#
#     http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.



@dataclass
class ConfigTest(Config):
    param: Any
    config: Optional[Config] = None


def test_config_repr():
    c1 = ConfigTest(param=1, config=ConfigTest(param=3))
    assert str(c1) == "ConfigTest(param=1, config=ConfigTest(param=3, config=None))"


def test_config_eq():
    basic_c = Config()
    c1 = ConfigTest(param=1)

# 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

# Copyright 2017--2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may not
# use this file except in compliance with the License. A copy of the License
# is located at
#
#     http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.



@dataclass
class ConfigTest(Config):
    param: Any
    config: Optional[Config] = None


def test_config_repr():
    c1 = ConfigTest(param=1, config=ConfigTest(param=3))
    assert str(c1) == "ConfigTest(param=1, config=ConfigTest(param=3, config=None))"


def test_config_eq():
    basic_c = Config()
    c1 = ConfigTest(param=1)

    c1_other = ConfigTest(param=1)