Skip to content

Commit

Permalink
Update broken OmegaConfigLoader test (#3696)
Browse files Browse the repository at this point in the history
* Add official support for Python 3.12

Close #3287.

Signed-off-by: Juan Luis Cano Rodríguez <juan_luis_cano@mckinsey.com>

* Mark broken test as xfail

Signed-off-by: Juan Luis Cano Rodríguez <juan_luis_cano@mckinsey.com>

* Overwrite inherited get to use __getitem__

Signed-off-by: Ahdra Merali <ahdra.merali@quantumblack.com>

* Appease mypy

Signed-off-by: Ahdra Merali <ahdra.merali@quantumblack.com>

* Fix test

Signed-off-by: Ahdra Merali <ahdra.merali@quantumblack.com>

* Fix test coverage

Signed-off-by: Ahdra Merali <ahdra.merali@quantumblack.com>

* Use spy instead of patch

Signed-off-by: Ahdra Merali <ahdra.merali@quantumblack.com>

* Make comment more clear

Signed-off-by: Ahdra Merali <ahdra.merali@quantumblack.com>

* Remove redundant test assert

Signed-off-by: Ahdra Merali <ahdra.merali@quantumblack.com>

* Remove redundant variable

Signed-off-by: Ahdra Merali <ahdra.merali@quantumblack.com>

* Fix broken docs link

Signed-off-by: Ahdra Merali <ahdra.merali@quantumblack.com>

* Fix broken docs link

Signed-off-by: Ahdra Merali <ahdra.merali@quantumblack.com>

* Update docstring to reflect test

Signed-off-by: Ahdra Merali <ahdra.merali@quantumblack.com>

* Add test to ensure deduplication

Signed-off-by: Ahdra Merali <ahdra.merali@quantumblack.com>

* Trim test

Signed-off-by: Ahdra Merali <ahdra.merali@quantumblack.com>

---------

Signed-off-by: Juan Luis Cano Rodríguez <juan_luis_cano@mckinsey.com>
Signed-off-by: Ahdra Merali <ahdra.merali@quantumblack.com>
Signed-off-by: Ahdra Merali <90615669+AhdraMeraliQB@users.noreply.github.com>
Co-authored-by: Juan Luis Cano Rodríguez <juan_luis_cano@mckinsey.com>
  • Loading branch information
AhdraMeraliQB and astrojuanlu authored Mar 15, 2024
1 parent 9efca0e commit 0b6e1a9
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions tests/config/test_omegaconf_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,8 @@ def test_empty_catalog_file(self, tmp_path):
)["catalog"]
assert catalog == {}

@pytest.mark.xfail(reason="Logic failing")
def test_overlapping_patterns(self, tmp_path, mocker):
"""Check that same configuration file is not loaded more than once."""
def test_overlapping_patterns(self, tmp_path):
"""Check that configuration is loaded correctly from overlapping patterns."""
_write_yaml(
tmp_path / _BASE_ENV / "catalog0.yml",
{"env": _BASE_ENV, "common": "common"},
Expand All @@ -424,7 +423,6 @@ def test_overlapping_patterns(self, tmp_path, mocker):
]
}

load_spy = mocker.spy(OmegaConf, "load")
catalog = OmegaConfigLoader(
conf_source=str(tmp_path),
base_env=_BASE_ENV,
Expand All @@ -439,9 +437,31 @@ def test_overlapping_patterns(self, tmp_path, mocker):
}
assert catalog == expected_catalog

# Assert any specific config file was only loaded once
expected_path = (tmp_path / "dev" / "user1" / "catalog2.yml").resolve()
load_spy.assert_called_once_with(expected_path)
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 / "user1" / "catalog.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 = {
"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
Expand Down

0 comments on commit 0b6e1a9

Please sign in to comment.