Repository: kedro-org/kedro
File: tests/config/test_omegaconf_config.py (Python)

Code before:
        base_params = tmp_path / _BASE_ENV / "parameters.yml"
        base_globals = tmp_path / _BASE_ENV / "globals.yml"
        param_config = {
            "my_global": "${globals:x}",
            "my_second_global": "${globals:new_key}",
        }
        globals_config = {
            "x": 45,
        }
        _write_yaml(base_params, param_config)
        _write_yaml(base_globals, globals_config)
        conf = OmegaConfigLoader(tmp_path, default_run_env="")
        conf["globals"] = {
            "x": 89,
            "new_key": 24,
        }
        assert conf["parameters"]["my_global"] == 89
        assert conf["parameters"]["my_second_global"] == 24


class TestOmegaConfigLoaderStandalone:
    """
    Test OmegaConfigLoader in standalone mode (defaults settings without environments)
    """

    def test_load_config_without_local(self, tmp_path):
        base_catalog = tmp_path / "catalog.yml"
        catalog_config = {
            "companies": {
                "type": "MemoryDataset",
                "filepath": "data/01_raw/companies.csv",
            },
        }
        _write_yaml(base_catalog, catalog_config)

        conf = OmegaConfigLoader(tmp_path)
        assert (
            conf["catalog"]["companies"]["type"] == catalog_config["companies"]["type"]
        )

    def test_variable_interpolation_in_catalog_with_templates(self, tmp_path):
        base_catalog = tmp_path / "catalog.yml"
        catalog_config = {
            "companies": {
                "type": "${_pandas.type}",
                "filepath": "data/01_raw/companies.csv",
            },
            "_pandas": {"type": "pandas.CSVDataset"},
        }
        _write_yaml(base_catalog, catalog_config)


Review comment (suggestion):
I think this test name isn't the best, because it uses assumptions what used to be the "default". I'd name this something like `test_load_config_without_environments`.

Code after:
        with pytest.raises(
            UnsupportedInterpolationType,
            match=r"Unsupported interpolation type non_existent_resolver",
        ):
            OmegaConfigLoader(
                tmp_path,
                base_env="",
                default_run_env="local",
                runtime_params=runtime_params,
            )

    def test_override_globals(self, tmp_path):
        """When globals are bypassed, make sure that the correct overwritten values are used"""
        base_params = tmp_path / _BASE_ENV / "parameters.yml"
        base_globals = tmp_path / _BASE_ENV / "globals.yml"
        param_config = {
            "my_global": "${globals:x}",
            "my_second_global": "${globals:new_key}",
        }
        globals_config = {
            "x": 45,
        }
        _write_yaml(base_params, param_config)
        _write_yaml(base_globals, globals_config)
        conf = OmegaConfigLoader(tmp_path, default_run_env="")
        conf["globals"] = {
            "x": 89,
            "new_key": 24,
        }
        assert conf["parameters"]["my_global"] == 89
        assert conf["parameters"]["my_second_global"] == 24


class TestOmegaConfigLoaderStandalone:
    """
    Test OmegaConfigLoader in standalone mode (defaults settings without environments)
    """

    def test_load_config_without_environment(self, tmp_path):
        base_catalog = tmp_path / "catalog.yml"
        catalog_config = {
            "companies": {
                "type": "MemoryDataset",
                "filepath": "data/01_raw/companies.csv",
            },
        }
        _write_yaml(base_catalog, catalog_config)

        conf = OmegaConfigLoader(tmp_path)
        assert (
            conf["catalog"]["companies"]["type"] == catalog_config["companies"]["type"]