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

Code before:
        )
        _write_yaml(tmp_path / _BASE_ENV / "user1" / "catalog2.yml", {"user1_c2": True})

        catalog_patterns = {
            "catalog": [
                "catalog*",
                "user1/catalog*",
                "*/catalog2*",
            ]
        }

        load_spy = mocker.spy(OmegaConf, "load")
        catalog = OmegaConfigLoader(
            conf_source=str(tmp_path),
            base_env=_BASE_ENV,
            config_patterns=catalog_patterns,
        )["catalog"]
        expected_catalog = {
            "env": "base",
            "common": "common",
            "user1_c2": True,
        }
        assert catalog == expected_catalog

        # Assert load is only called once for each file
        assert load_spy.call_count == 2

    def test_yaml_parser_error(self, tmp_path):
        conf_path = tmp_path / _BASE_ENV
        conf_path.mkdir(parents=True, exist_ok=True)

        example_catalog = """
        example_iris_data:
              type: pandas.CSVDataset
          filepath: data/01_raw/iris.csv
        """

        (conf_path / "catalog.yml").write_text(example_catalog)

        msg = (
            f"Invalid YAML or JSON file {Path(conf_path, 'catalog.yml').as_posix()}, unable to read"
            f" line 3, position 10."
        )
        with pytest.raises(ParserError, match=re.escape(msg)):
            OmegaConfigLoader(
                str(tmp_path), base_env=_BASE_ENV, default_run_env=_DEFAULT_RUN_ENV
            )["catalog"]

    def test_customised_config_patterns(self, tmp_path):
        config_loader = OmegaConfigLoader(
            conf_source=str(tmp_path),

Review comment (suggestion):
I tested it and it works fine. I think one improvement we can make is simply remove anything about `catalog0.yml`, since the test is focusing on the deduplication, only catalog 2 is being scan twice but read once. It also make the test simpler.

Code after:
            "catalog": [
                "catalog*",
                "user1/catalog*",
                "*/catalog2*",
            ]
        }

        load_spy = mocker.spy(OmegaConf, "load")
        catalog = OmegaConfigLoader(
            conf_source=str(tmp_path),
            base_env=_BASE_ENV,
            config_patterns=catalog_patterns,
        )["catalog"]
        expected_catalog = {
            "user1_c2": True,
        }
        assert catalog == expected_catalog

        # Assert load is only called once
        load_spy.assert_called_once()

    def test_yaml_parser_error(self, tmp_path):
        conf_path = tmp_path / _BASE_ENV
        conf_path.mkdir(parents=True, exist_ok=True)

        example_catalog = """
        example_iris_data:
              type: pandas.CSVDataset
          filepath: data/01_raw/iris.csv
        """

        (conf_path / "catalog.yml").write_text(example_catalog)

        msg = (
            f"Invalid YAML or JSON file {Path(conf_path, 'catalog.yml').as_posix()}, unable to read"
            f" line 3, position 10."
        )
        with pytest.raises(ParserError, match=re.escape(msg)):
            OmegaConfigLoader(
                str(tmp_path), base_env=_BASE_ENV, default_run_env=_DEFAULT_RUN_ENV
            )["catalog"]

    def test_customised_config_patterns(self, tmp_path):
        config_loader = OmegaConfigLoader(
            conf_source=str(tmp_path),
            config_patterns={
                "spark": ["spark*/"],
                "parameters": ["params*", "params*/**", "**/params*"],
            },
        )
        assert config_loader.config_patterns["catalog"] == [