# Path: clouddq/classes/metadata_registry_defaults.py
# class MetadataRegistryDefaults:
#     """ """
# 
#     default_configs: dict
# 
#     @classmethod
#     def from_dict(
#         cls: MetadataRegistryDefaults, kwargs: dict
#     ) -> MetadataRegistryDefaults:
#         default_configs = {}
#         logger.debug(f"Parsing input 'metadata_registry_defaults':\n {pformat(kwargs)}")
#         for registry_scheme, registry_defaults in kwargs.items():
#             scheme = EntityUriScheme.from_scheme(registry_scheme)
#             default_configs[scheme.value] = {}
#             expected_uri_fields = None
#             if scheme == EntityUriScheme.DATAPLEX:
#                 expected_uri_fields = DATAPLEX_URI_FIELDS
#             else:
#                 raise NotImplementedError(
#                     f"'metadata_registry_default' not implemented for registry '{scheme}' "
#                 )
#             for key, value in registry_defaults.items():
#                 if key not in expected_uri_fields:
#                     raise ValueError(
#                         f"'metadata_registry_default' for scheme '{scheme}' "
#                         f"contains unexpected field '{key}'."
#                     )
#                 default_configs[scheme][key] = value
#         return MetadataRegistryDefaults(default_configs=default_configs)
# 
#     def to_dict(self: MetadataRegistryDefaults) -> dict:
#         return self.default_configs
# 
#     def get_dataplex_registry_defaults(self, key: str | None = None) -> str | None:
#         if self.default_configs.get("DATAPLEX", None):
#             if key:
#                 return self.default_configs["DATAPLEX"].get(key, None)
#             else:
#                 return self.default_configs["DATAPLEX"]
#         else:
#             return None
# 
# Path: clouddq/lib.py
# def load_metadata_registry_default_configs(
#     configs_path: Path,
# ) -> MetadataRegistryDefaults:
#     configs = load_configs(configs_path, DqConfigType.METADATA_REGISTRY_DEFAULTS)
#     try:
#         return MetadataRegistryDefaults.from_dict(configs)
#     except ValueError as e:
#         logger.warning(e)
#         return MetadataRegistryDefaults.from_dict({})


from pathlib import Path
from clouddq.classes.metadata_registry_defaults import MetadataRegistryDefaults
from clouddq.lib import load_metadata_registry_default_configs
import logging
import os
import shutil
import pytest
import yaml

    def test_from_dict_metadata_registry_default_configs(self, dataplex_expected_defaults):
        metadata_registry_defaults = MetadataRegistryDefaults.from_dict(dataplex_expected_defaults)
        assert metadata_registry_defaults.to_dict() == dataplex_expected_defaults

    def test_from_dict_metadata_registry_default_configs_unsupported(self):
        input_dict = {
            "bigquery": {
                "projects": "<my-gcp-project-id>",
            }
        }
        with pytest.raises(NotImplementedError):
            MetadataRegistryDefaults.from_dict(input_dict)

    def test_from_dict_metadata_registry_default_configs_unexpected_key(self):
        input_dict = {
            "DATAPLEX": {
                "dataset": "<my-gcp-bq-dataset>",
            }
        }
        with pytest.raises(ValueError):
            MetadataRegistryDefaults.from_dict(input_dict)

    def test_load_undefined_configs_ok(self, tmp_path):
        # Load a config directory containing two copies of the same config
        try:
            temp_dir = Path(tmp_path).joinpath("clouddq_test_metadata_registry_defaults_0")
            temp_dir.mkdir(parents=True)

            loaded_config = load_metadata_registry_default_configs(temp_dir)

# Path: clouddq/classes/metadata_registry_defaults.py
# class MetadataRegistryDefaults:
#     """ """
# 
#     default_configs: dict
# 
#     @classmethod
#     def from_dict(
#         cls: MetadataRegistryDefaults, kwargs: dict
#     ) -> MetadataRegistryDefaults:
#         default_configs = {}
#         logger.debug(f"Parsing input 'metadata_registry_defaults':\n {pformat(kwargs)}")
#         for registry_scheme, registry_defaults in kwargs.items():
#             scheme = EntityUriScheme.from_scheme(registry_scheme)
#             default_configs[scheme.value] = {}
#             expected_uri_fields = None
#             if scheme == EntityUriScheme.DATAPLEX:
#                 expected_uri_fields = DATAPLEX_URI_FIELDS
#             else:
#                 raise NotImplementedError(
#                     f"'metadata_registry_default' not implemented for registry '{scheme}' "
#                 )
#             for key, value in registry_defaults.items():
#                 if key not in expected_uri_fields:
#                     raise ValueError(
#                         f"'metadata_registry_default' for scheme '{scheme}' "
#                         f"contains unexpected field '{key}'."
#                     )
#                 default_configs[scheme][key] = value
#         return MetadataRegistryDefaults(default_configs=default_configs)
# 
#     def to_dict(self: MetadataRegistryDefaults) -> dict:
#         return self.default_configs
# 
#     def get_dataplex_registry_defaults(self, key: str | None = None) -> str | None:
#         if self.default_configs.get("DATAPLEX", None):
#             if key:
#                 return self.default_configs["DATAPLEX"].get(key, None)
#             else:
#                 return self.default_configs["DATAPLEX"]
#         else:
#             return None
# 
# Path: clouddq/lib.py
# def load_metadata_registry_default_configs(
#     configs_path: Path,
# ) -> MetadataRegistryDefaults:
#     configs = load_configs(configs_path, DqConfigType.METADATA_REGISTRY_DEFAULTS)
#     try:
#         return MetadataRegistryDefaults.from_dict(configs)
#     except ValueError as e:
#         logger.warning(e)
#         return MetadataRegistryDefaults.from_dict({})


# Path: tests/unit/test_metadata_registry_defaults.py
from pathlib import Path
from clouddq.classes.metadata_registry_defaults import MetadataRegistryDefaults
from clouddq.lib import load_metadata_registry_default_configs
import logging
import os
import shutil
import pytest
import yaml


    def test_from_dict_metadata_registry_default_configs(self, dataplex_expected_defaults):
        metadata_registry_defaults = MetadataRegistryDefaults.from_dict(dataplex_expected_defaults)
        assert metadata_registry_defaults.to_dict() == dataplex_expected_defaults

    def test_from_dict_metadata_registry_default_configs_unsupported(self):
        input_dict = {
            "bigquery": {
                "projects": "<my-gcp-project-id>",
            }
        }
        with pytest.raises(NotImplementedError):
            MetadataRegistryDefaults.from_dict(input_dict)

    def test_from_dict_metadata_registry_default_configs_unexpected_key(self):
        input_dict = {
            "DATAPLEX": {
                "dataset": "<my-gcp-bq-dataset>",
            }
        }
        with pytest.raises(ValueError):
            MetadataRegistryDefaults.from_dict(input_dict)

    def test_load_undefined_configs_ok(self, tmp_path):
        # Load a config directory containing two copies of the same config
        try:
            temp_dir = Path(tmp_path).joinpath("clouddq_test_metadata_registry_defaults_0")
            temp_dir.mkdir(parents=True)

            loaded_config = load_metadata_registry_default_configs(temp_dir)

            assert type(loaded_config) == MetadataRegistryDefaults