From cc28696dec8703b95457f9f3d405fc039eb7aafb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Luis=20Cano=20Rodr=C3=ADguez?= Date: Fri, 2 Feb 2024 09:05:01 +0100 Subject: [PATCH 01/15] Add official support for Python 3.12 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Close #3287. Signed-off-by: Juan Luis Cano Rodríguez --- .github/workflows/all-checks.yml | 6 +++--- .github/workflows/docs-only-checks.yml | 2 +- RELEASE.md | 1 + kedro/__init__.py | 2 +- tests/test_import.py | 8 ++++---- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/all-checks.yml b/.github/workflows/all-checks.yml index f63de1fbbc..2dfb971e3d 100644 --- a/.github/workflows/all-checks.yml +++ b/.github/workflows/all-checks.yml @@ -26,7 +26,7 @@ jobs: strategy: matrix: os: [ windows-latest, ubuntu-latest ] - python-version: [ "3.8", "3.9", "3.10", "3.11" ] + python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ] uses: ./.github/workflows/unit-tests.yml with: os: ${{ matrix.os }} @@ -36,7 +36,7 @@ jobs: strategy: matrix: os: [ windows-latest, ubuntu-latest ] - python-version: [ "3.8", "3.9", "3.10", "3.11" ] + python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ] uses: ./.github/workflows/e2e-tests.yml with: os: ${{ matrix.os }} @@ -59,7 +59,7 @@ jobs: strategy: matrix: os: [ windows-latest, ubuntu-latest ] - python-version: [ "3.8", "3.9", "3.10", "3.11" ] + python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ] uses: ./.github/workflows/pip-compile.yml with: os: ${{ matrix.os }} diff --git a/.github/workflows/docs-only-checks.yml b/.github/workflows/docs-only-checks.yml index 1af4aa53e8..d0cca88abd 100644 --- a/.github/workflows/docs-only-checks.yml +++ b/.github/workflows/docs-only-checks.yml @@ -21,7 +21,7 @@ jobs: strategy: matrix: os: [ ubuntu-latest ] - python-version: [ "3.8", "3.9", "3.10", "3.11" ] + python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ] uses: ./.github/workflows/lint.yml with: os: ${{ matrix.os }} diff --git a/RELEASE.md b/RELEASE.md index 2ca1de007e..d8564ac462 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -2,6 +2,7 @@ ## Major features and improvements * Create the debugging line magic `%load_node` for Jupyter Notebook and Jupyter Lab. +* Add official support for Python 3.12. ## Bug fixes and other changes * Updated CLI Command `kedro catalog resolve` to work with dataset factories that use `PartitionedDataset`. diff --git a/kedro/__init__.py b/kedro/__init__.py index a538fcbecc..53a31804b3 100644 --- a/kedro/__init__.py +++ b/kedro/__init__.py @@ -21,7 +21,7 @@ class KedroPythonVersionWarning(UserWarning): warnings.simplefilter("default", KedroDeprecationWarning) warnings.simplefilter("error", KedroPythonVersionWarning) -if sys.version_info >= (3, 12): +if sys.version_info >= (3, 13): warnings.warn( """Kedro is not yet fully compatible with this Python version. To proceed at your own risk and ignore this warning, diff --git a/tests/test_import.py b/tests/test_import.py index a9aa72e21a..6dc9da4df4 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -4,8 +4,8 @@ def test_import_kedro_with_no_official_support_raise_error(mocker): - """Test importing kedro with python>=3.12 should fail""" - mocker.patch("kedro.sys.version_info", (3, 12)) + """Test importing kedro with python>=3.13 should fail""" + mocker.patch("kedro.sys.version_info", (3, 13)) # We use the parent class to avoid issues with `exec_module` with pytest.raises(UserWarning) as excinfo: @@ -15,8 +15,8 @@ def test_import_kedro_with_no_official_support_raise_error(mocker): def test_import_kedro_with_no_official_support_emits_warning(mocker): - """Test importing kedro python>=3.12 and controlled warnings should work""" - mocker.patch("kedro.sys.version_info", (3, 12)) + """Test importing kedro python>=3.13 and controlled warnings should work""" + mocker.patch("kedro.sys.version_info", (3, 13)) mocker.patch("kedro.sys.warnoptions", ["default:Kedro is not yet fully compatible"]) # We use the parent class to avoid issues with `exec_module` From 74705b868895f5c1f73c5321a2d93765330dda5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Luis=20Cano=20Rodr=C3=ADguez?= Date: Fri, 2 Feb 2024 17:38:33 +0100 Subject: [PATCH 02/15] Mark broken test as xfail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Juan Luis Cano Rodríguez --- tests/config/test_omegaconf_config.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/config/test_omegaconf_config.py b/tests/config/test_omegaconf_config.py index c820bf4d0c..d26b7e37ae 100644 --- a/tests/config/test_omegaconf_config.py +++ b/tests/config/test_omegaconf_config.py @@ -401,6 +401,7 @@ def test_empty_catalog_file(self, tmp_path): )["catalog"] assert catalog == {} + @pytest.mark.xfail(reason="Pending fix") def test_overlapping_patterns(self, tmp_path, mocker): """Check that same configuration file is not loaded more than once.""" _write_yaml( @@ -437,7 +438,8 @@ def test_overlapping_patterns(self, tmp_path, mocker): mocked_load = mocker.patch("omegaconf.OmegaConf.load") expected_path = (tmp_path / "dev" / "user1" / "catalog2.yml").resolve() - assert mocked_load.called_once_with(expected_path) + + mocked_load.assert_called_once_with(expected_path) def test_yaml_parser_error(self, tmp_path): conf_path = tmp_path / _BASE_ENV From 4dc83f202794708315102a62d710451dd9a34101 Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Fri, 8 Mar 2024 13:43:30 +0000 Subject: [PATCH 03/15] Overwrite inherited get to use __getitem__ Signed-off-by: Ahdra Merali --- kedro/config/abstract_config.py | 9 +++++++++ tests/config/test_omegaconf_config.py | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/kedro/config/abstract_config.py b/kedro/config/abstract_config.py index 60b75fcba8..ade8b522f4 100644 --- a/kedro/config/abstract_config.py +++ b/kedro/config/abstract_config.py @@ -26,6 +26,15 @@ def __init__( self.env = env self.runtime_params = runtime_params or {} + # From Python 3.12 __getitem__ isn't called in UserDict.get() + # Use the version from 3.11 and prior + def get(self, key, default=None): + "D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None." + try: + return self[key] + except KeyError: + return default + class BadConfigException(Exception): """Raised when a configuration file cannot be loaded, for instance diff --git a/tests/config/test_omegaconf_config.py b/tests/config/test_omegaconf_config.py index d26b7e37ae..34171a91c7 100644 --- a/tests/config/test_omegaconf_config.py +++ b/tests/config/test_omegaconf_config.py @@ -401,7 +401,8 @@ def test_empty_catalog_file(self, tmp_path): )["catalog"] assert catalog == {} - @pytest.mark.xfail(reason="Pending fix") + # @pytest.mark.xfail(reason="Pending fix") + # TODO rewrite this test def test_overlapping_patterns(self, tmp_path, mocker): """Check that same configuration file is not loaded more than once.""" _write_yaml( From d01541f61e5484b15a626d1814c84a05665a0a3d Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Fri, 8 Mar 2024 13:49:47 +0000 Subject: [PATCH 04/15] Appease mypy Signed-off-by: Ahdra Merali --- kedro/config/abstract_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kedro/config/abstract_config.py b/kedro/config/abstract_config.py index ade8b522f4..9008036c96 100644 --- a/kedro/config/abstract_config.py +++ b/kedro/config/abstract_config.py @@ -28,7 +28,7 @@ def __init__( # From Python 3.12 __getitem__ isn't called in UserDict.get() # Use the version from 3.11 and prior - def get(self, key, default=None): + def get(self, key: str, default: Any = None) -> Any: "D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None." try: return self[key] From 43ab5441f7fdb5a82ba2c3516d53b5b3c4d57442 Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Fri, 8 Mar 2024 14:16:22 +0000 Subject: [PATCH 05/15] Fix test Signed-off-by: Ahdra Merali --- tests/config/test_omegaconf_config.py | 40 ++++++++++++++------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/tests/config/test_omegaconf_config.py b/tests/config/test_omegaconf_config.py index 34171a91c7..95ea74b78e 100644 --- a/tests/config/test_omegaconf_config.py +++ b/tests/config/test_omegaconf_config.py @@ -401,8 +401,7 @@ def test_empty_catalog_file(self, tmp_path): )["catalog"] assert catalog == {} - # @pytest.mark.xfail(reason="Pending fix") - # TODO rewrite this test + @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.""" _write_yaml( @@ -423,24 +422,27 @@ def test_overlapping_patterns(self, tmp_path, mocker): ] } - catalog = OmegaConfigLoader( - conf_source=str(tmp_path), - base_env=_BASE_ENV, - env="dev", - config_patterns=catalog_patterns, - )["catalog"] - expected_catalog = { - "env": "dev", - "common": "common", - "dev_specific": "wiz", - "user1_c2": True, - } - assert catalog == expected_catalog - - mocked_load = mocker.patch("omegaconf.OmegaConf.load") - expected_path = (tmp_path / "dev" / "user1" / "catalog2.yml").resolve() + # Use a mocked function to keep track of function calls + with mocker.patch( + "omegaconf.OmegaConf.load", wraps=OmegaConf.load + ) as mocked_load: + catalog = OmegaConfigLoader( + conf_source=str(tmp_path), + base_env=_BASE_ENV, + env="dev", + config_patterns=catalog_patterns, + )["catalog"] + expected_catalog = { + "env": "dev", + "common": "common", + "dev_specific": "wiz", + "user1_c2": True, + } + assert catalog == expected_catalog - mocked_load.assert_called_once_with(expected_path) + # Assert any specific config file was only loaded once + expected_path = (tmp_path / "dev" / "user1" / "catalog2.yml").resolve() + mocked_load.assert_called_once_with(expected_path) def test_yaml_parser_error(self, tmp_path): conf_path = tmp_path / _BASE_ENV From 62481cca46f690274814e5387deb3cff367438be Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Fri, 8 Mar 2024 14:26:25 +0000 Subject: [PATCH 06/15] Fix test coverage Signed-off-by: Ahdra Merali --- tests/config/test_omegaconf_config.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/config/test_omegaconf_config.py b/tests/config/test_omegaconf_config.py index 95ea74b78e..7f96d373d0 100644 --- a/tests/config/test_omegaconf_config.py +++ b/tests/config/test_omegaconf_config.py @@ -175,9 +175,11 @@ def test_load_core_config_get_syntax(self, tmp_path): ) params = conf.get("parameters") catalog = conf.get("catalog") + missing_conf = conf.get("missing_conf") assert params["param1"] == 1 assert catalog["trains"]["type"] == "MemoryDataset" + assert missing_conf == None @use_config_dir def test_load_local_config_overrides_base(self, tmp_path): From f459d2f444cddbdb5d56e467ec6d834a38debb2f Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Fri, 8 Mar 2024 14:41:16 +0000 Subject: [PATCH 07/15] Use spy instead of patch Signed-off-by: Ahdra Merali --- tests/config/test_omegaconf_config.py | 37 ++++++++++++--------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/tests/config/test_omegaconf_config.py b/tests/config/test_omegaconf_config.py index 7f96d373d0..a68ba3b623 100644 --- a/tests/config/test_omegaconf_config.py +++ b/tests/config/test_omegaconf_config.py @@ -424,27 +424,24 @@ def test_overlapping_patterns(self, tmp_path, mocker): ] } - # Use a mocked function to keep track of function calls - with mocker.patch( - "omegaconf.OmegaConf.load", wraps=OmegaConf.load - ) as mocked_load: - catalog = OmegaConfigLoader( - conf_source=str(tmp_path), - base_env=_BASE_ENV, - env="dev", - config_patterns=catalog_patterns, - )["catalog"] - expected_catalog = { - "env": "dev", - "common": "common", - "dev_specific": "wiz", - "user1_c2": True, - } - assert catalog == expected_catalog + load_spy = mocker.spy(OmegaConf, "load") + catalog = OmegaConfigLoader( + conf_source=str(tmp_path), + base_env=_BASE_ENV, + env="dev", + config_patterns=catalog_patterns, + )["catalog"] + expected_catalog = { + "env": "dev", + "common": "common", + "dev_specific": "wiz", + "user1_c2": True, + } + assert catalog == expected_catalog - # Assert any specific config file was only loaded once - expected_path = (tmp_path / "dev" / "user1" / "catalog2.yml").resolve() - mocked_load.assert_called_once_with(expected_path) + # 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_yaml_parser_error(self, tmp_path): conf_path = tmp_path / _BASE_ENV From 9afc366b3a1e3d5b0ad4f0df5583be09739bfa93 Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Fri, 8 Mar 2024 14:46:49 +0000 Subject: [PATCH 08/15] Make comment more clear Signed-off-by: Ahdra Merali --- kedro/config/abstract_config.py | 6 ++++-- tests/config/test_omegaconf_config.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/kedro/config/abstract_config.py b/kedro/config/abstract_config.py index 9008036c96..a7edf83187 100644 --- a/kedro/config/abstract_config.py +++ b/kedro/config/abstract_config.py @@ -26,8 +26,10 @@ def __init__( self.env = env self.runtime_params = runtime_params or {} - # From Python 3.12 __getitem__ isn't called in UserDict.get() - # Use the version from 3.11 and prior + # As of Python 3.12 __getitem__ is no longer called in the inherited UserDict.get() + # This causes AbstractConfigLoader.get() to break + # See: https://github.com/python/cpython/issues/105524 + # Overwrite the inherited get function with the implementation from 3.11 and prior def get(self, key: str, default: Any = None) -> Any: "D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None." try: diff --git a/tests/config/test_omegaconf_config.py b/tests/config/test_omegaconf_config.py index a68ba3b623..b0b66fa667 100644 --- a/tests/config/test_omegaconf_config.py +++ b/tests/config/test_omegaconf_config.py @@ -179,7 +179,7 @@ def test_load_core_config_get_syntax(self, tmp_path): assert params["param1"] == 1 assert catalog["trains"]["type"] == "MemoryDataset" - assert missing_conf == None + assert missing_conf is None @use_config_dir def test_load_local_config_overrides_base(self, tmp_path): From 642822f93df655597af3a257c070df0a501c3287 Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Tue, 12 Mar 2024 09:34:37 +0000 Subject: [PATCH 09/15] Remove redundant test assert Signed-off-by: Ahdra Merali --- tests/config/test_omegaconf_config.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/config/test_omegaconf_config.py b/tests/config/test_omegaconf_config.py index b0b66fa667..f07264a8a3 100644 --- a/tests/config/test_omegaconf_config.py +++ b/tests/config/test_omegaconf_config.py @@ -403,7 +403,7 @@ def test_empty_catalog_file(self, tmp_path): )["catalog"] assert catalog == {} - @pytest.mark.xfail(reason="Logic failing") + # @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.""" _write_yaml( @@ -439,10 +439,6 @@ 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_yaml_parser_error(self, tmp_path): conf_path = tmp_path / _BASE_ENV conf_path.mkdir(parents=True, exist_ok=True) From bdadc8dde4f723952caa59182745a430a05dccab Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Tue, 12 Mar 2024 10:10:24 +0000 Subject: [PATCH 10/15] Remove redundant variable Signed-off-by: Ahdra Merali --- tests/config/test_omegaconf_config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/config/test_omegaconf_config.py b/tests/config/test_omegaconf_config.py index f07264a8a3..eb5fc1227f 100644 --- a/tests/config/test_omegaconf_config.py +++ b/tests/config/test_omegaconf_config.py @@ -424,7 +424,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, From 6e6324a8ff5db48bd6189a0193a37229dedd76b3 Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Tue, 12 Mar 2024 10:24:21 +0000 Subject: [PATCH 11/15] Fix broken docs link Signed-off-by: Ahdra Merali --- docs/source/data/how_to_create_a_custom_dataset.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/data/how_to_create_a_custom_dataset.md b/docs/source/data/how_to_create_a_custom_dataset.md index 73a074e49e..0793ee1e3b 100644 --- a/docs/source/data/how_to_create_a_custom_dataset.md +++ b/docs/source/data/how_to_create_a_custom_dataset.md @@ -9,7 +9,7 @@ If you are a contributor and would like to submit a new dataset, you must extend ## Scenario -In this example, we use a [Kaggle dataset of Pokémon images and types](https://www.kaggle.com/vishalsubbiah/pokemon-images-and-types) to train a model to classify the type of a given [Pokémon](https://en.wikipedia.org/wiki/Pok%C3%A9mon), e.g. Water, Fire, Bug, etc., based on its appearance. To train the model, we read the Pokémon images from PNG files into `numpy` arrays before further manipulation in the Kedro pipeline. To work with PNG images out of the box, in this example we create an `ImageDataset` to read and save image data. +In this example, we use a [Kaggle dataset of Pokémon images and types](https://www.kaggle.com/datasets/vishalsubbiah/pokemon-images-and-types) to train a model to classify the type of a given [Pokémon](https://en.wikipedia.org/wiki/Pok%C3%A9mon), e.g. Water, Fire, Bug, etc., based on its appearance. To train the model, we read the Pokémon images from PNG files into `numpy` arrays before further manipulation in the Kedro pipeline. To work with PNG images out of the box, in this example we create an `ImageDataset` to read and save image data. ## Project setup From 2ed5ce0b4613e49085833e17e549afae29ff9dc9 Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Tue, 12 Mar 2024 10:37:59 +0000 Subject: [PATCH 12/15] Fix broken docs link Signed-off-by: Ahdra Merali --- docs/source/data/how_to_create_a_custom_dataset.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/data/how_to_create_a_custom_dataset.md b/docs/source/data/how_to_create_a_custom_dataset.md index 0793ee1e3b..62c1841056 100644 --- a/docs/source/data/how_to_create_a_custom_dataset.md +++ b/docs/source/data/how_to_create_a_custom_dataset.md @@ -15,7 +15,7 @@ In this example, we use a [Kaggle dataset of Pokémon images and types](https:// We assume that you have already [installed Kedro](../get_started/install.md). Now [create a project](../get_started/new_project.md) (feel free to name your project as you like, but here we will assume the project's repository name is `kedro-pokemon`). -Log into your Kaggle account to [download the Pokémon dataset](https://www.kaggle.com/vishalsubbiah/pokemon-images-and-types) and unzip it into `data/01_raw`, within a subfolder named `pokemon-images-and-types`. The data comprises a single `pokemon.csv` file plus a subfolder of images. +Log into your Kaggle account to [download the Pokémon dataset](https://www.kaggle.com/datasets/vishalsubbiah/pokemon-images-and-types) and unzip it into `data/01_raw`, within a subfolder named `pokemon-images-and-types`. The data comprises a single `pokemon.csv` file plus a subfolder of images. The dataset will use [Pillow](https://pillow.readthedocs.io/en/stable/) for generic image processing functionality, to ensure that it can work with a range of different image formats, not just PNG. From 9a4963fd41dfd34db07147d9f94edff3c48da521 Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Wed, 13 Mar 2024 16:04:14 +0000 Subject: [PATCH 13/15] Update docstring to reflect test Signed-off-by: Ahdra Merali --- tests/config/test_omegaconf_config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/config/test_omegaconf_config.py b/tests/config/test_omegaconf_config.py index c22a132744..b6aec81820 100644 --- a/tests/config/test_omegaconf_config.py +++ b/tests/config/test_omegaconf_config.py @@ -403,8 +403,8 @@ def test_empty_catalog_file(self, tmp_path): )["catalog"] assert catalog == {} - 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"}, From 02bf45eecbb30998ef9716f38b7f2002f56dc143 Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Thu, 14 Mar 2024 09:56:31 +0000 Subject: [PATCH 14/15] Add test to ensure deduplication Signed-off-by: Ahdra Merali --- tests/config/test_omegaconf_config.py | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/config/test_omegaconf_config.py b/tests/config/test_omegaconf_config.py index b6aec81820..695039db51 100644 --- a/tests/config/test_omegaconf_config.py +++ b/tests/config/test_omegaconf_config.py @@ -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) From 6314091ac0e8e3c8fc0cbf9cedb52911b7f0c4ad Mon Sep 17 00:00:00 2001 From: Ahdra Merali Date: Thu, 14 Mar 2024 16:07:55 +0000 Subject: [PATCH 15/15] Trim test Signed-off-by: Ahdra Merali --- tests/config/test_omegaconf_config.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/tests/config/test_omegaconf_config.py b/tests/config/test_omegaconf_config.py index 695039db51..3ec2b39074 100644 --- a/tests/config/test_omegaconf_config.py +++ b/tests/config/test_omegaconf_config.py @@ -439,11 +439,7 @@ def test_overlapping_patterns(self, tmp_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 / "catalog0.yml", - {"env": "base", "common": "common"}, - ) - _write_yaml(tmp_path / _BASE_ENV / "user1" / "catalog2.yml", {"user1_c2": True}) + _write_yaml(tmp_path / _BASE_ENV / "user1" / "catalog.yml", {"user1_c2": True}) catalog_patterns = { "catalog": [ @@ -460,14 +456,12 @@ def test_overlapping_patterns_in_same_env(self, tmp_path, mocker): 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 + # 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