Skip to content

Commit

Permalink
Write settings.yml parameters in original order (#2352)
Browse files Browse the repository at this point in the history
Co-authored-by: Eneko Martin <[email protected]>
  • Loading branch information
enekomartinmartinez and Eneko Martin authored Jul 17, 2024
1 parent 15dc3a0 commit 1716cb8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion esmvalcore/_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def write_settings(self):
settings_copy.pop(sett, None)

filename = run_dir / 'settings.yml'
filename.write_text(yaml.safe_dump(settings_copy))
filename.write_text(yaml.safe_dump(settings_copy, sort_keys=False))

# If running an NCL script:
if Path(self.script).suffix.lower() == '.ncl':
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from multiprocessing.pool import ThreadPool

import pytest
import yaml

import esmvalcore
from esmvalcore._task import (
Expand Down Expand Up @@ -245,6 +246,23 @@ def test_py_diagnostic_task_constructor(tmp_path):
assert task.output_dir == tmp_path / 'mydiag'


def test_py_diagnostic_task_write_settings(tmp_path):
"""Test DiagnosticTask writtes settings in the user's order."""
diag_script = tmp_path / 'diag_cow.py'
task = _get_single_diagnostic_task(tmp_path, diag_script)
my_arg_dict = {
'b': [1],
'a': 3.,
'c': False
}
task.settings.update(my_arg_dict)
settings = task.write_settings()
with open(settings, 'r') as stream:
settings_data = yaml.safe_load(stream)

assert list(settings_data) == ['run_dir', 'b', 'a', 'c']


def test_diagnostic_diag_script_none(tmp_path):
"""Test case when diagnostic script doesn't exist."""
diag_script = tmp_path / 'diag_cow.py'
Expand Down

0 comments on commit 1716cb8

Please sign in to comment.