Skip to content

Commit

Permalink
Add test to ensure deduplication
Browse files Browse the repository at this point in the history
Signed-off-by: Ahdra Merali <[email protected]>
  • Loading branch information
Ahdra Merali committed Mar 14, 2024
1 parent 9a4963f commit 02bf45e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/config/test_omegaconf_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,38 @@ def test_overlapping_patterns(self, tmp_path):
}
assert catalog == expected_catalog

def test_overlapping_patterns_in_same_env(self, tmp_path, mocker):
"""Check that configuration files that match several patterns are only loaded once in each env."""
_write_yaml(
tmp_path / _BASE_ENV / "catalog0.yml",
{"env": "base", "common": "common"},
)
_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)
Expand Down

0 comments on commit 02bf45e

Please sign in to comment.