-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a CLI to dump the Hydra configuration files into a single Y…
…AML file. (#137) Add a CLI to dump the Hydra configuration files into a single YAML file. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
9331e63
commit ef1e76e
Showing
2 changed files
with
106 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# (C) Copyright 2024 Anemoi contributors. | ||
# | ||
# This software is licensed under the terms of the Apache Licence Version 2.0 | ||
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# In applying this licence, ECMWF does not waive the privileges and immunities | ||
# granted to it by virtue of its status as an intergovernmental organisation | ||
# nor does it submit to any jurisdiction. | ||
|
||
|
||
import tempfile | ||
from pathlib import Path | ||
from unittest import mock | ||
|
||
import pytest | ||
from omegaconf import OmegaConf | ||
|
||
from anemoi.training.commands.config import ConfigGenerator | ||
|
||
|
||
@pytest.fixture | ||
def config_generator() -> ConfigGenerator: | ||
return ConfigGenerator() | ||
|
||
|
||
def test_dump_config(config_generator: ConfigGenerator) -> None: | ||
with tempfile.TemporaryDirectory() as tmpdirname: | ||
config_path = Path(tmpdirname) / "config" | ||
config_path.mkdir(parents=True, exist_ok=True) | ||
(config_path / "test.yaml").write_text("test: value") | ||
|
||
output_path = Path(tmpdirname) / "output.yaml" | ||
with mock.patch("anemoi.training.commands.config.ConfigGenerator.copy_files") as mock_copy_files, mock.patch( | ||
"anemoi.training.commands.config.initialize", | ||
), mock.patch("anemoi.training.commands.config.compose", return_value=OmegaConf.create({"test": "value"})): | ||
config_generator.dump_config(config_path, "test", output_path) | ||
|
||
mock_copy_files.assert_called_once_with(config_path, mock.ANY) | ||
assert output_path.exists() | ||
assert OmegaConf.load(output_path) == {"test": "value"} |