Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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