Skip to content

Commit 87be0fc

Browse files
committed
MAINT: Make 'oyaml' private
1 parent 38f45e4 commit 87be0fc

6 files changed

Lines changed: 69 additions & 10 deletions

File tree

src/fmu/config/_configparserfmu_ipl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def _guess_dtype(var: str, entry: dict[str, Any]) -> dict[str, Any]:
238238
keyword = var
239239
logger.info("Guess dtype and value(s) for %s %s", var, values)
240240

241-
usekey = OrderedDict()
241+
usekey: OrderedDict = OrderedDict()
242242
usekey[keyword] = OrderedDict()
243243
usekey[keyword]["dtype"] = None
244244
usekey[keyword]["value"] = None # Keep "value" if singel entry

src/fmu/config/configparserfmu.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,19 @@
1414
import re
1515
import socket
1616
import sys
17-
18-
# for ordered dicts!
1917
from collections import Counter, OrderedDict
2018
from copy import deepcopy
2119
from os.path import join as ojoin
2220
from typing import TYPE_CHECKING
2321

22+
from fmu.config import _configparserfmu_ipl, _oyaml as yaml, etc
23+
from fmu.config._loader import ConstructorError, FmuLoader
24+
2425
try:
2526
from fmu.config.version import __version__
2627
except ImportError:
2728
__version__ = "0.0.0"
2829

29-
from fmu.config import _configparserfmu_ipl, etc, oyaml as yaml
30-
from fmu.config._loader import ConstructorError, FmuLoader
31-
3230
if TYPE_CHECKING:
3331
from typing import Any, Literal
3432

src/fmu/config/utilities.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
from __future__ import annotations
44

5+
from yaml.loader import Loader
6+
57
from fmu.config import _oyaml as yaml
68
from fmu.config._loader import ConstructorError, FmuLoader
7-
from yaml.loader import Loader
89

910

1011
def yaml_load(

tests/test_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import os.path
55
from os.path import join
66

7-
import fmu.config as config
87
import pytest
9-
from fmu.config import _oyaml as yaml
10-
from fmu.config import utilities as ut
8+
9+
import fmu.config as config
10+
from fmu.config import _oyaml as yaml, utilities as ut
1111

1212
# import fmu.config.fmuconfigrunner as fmurun
1313

tests/test_etc.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
import pytest
77
import yaml
8+
from pytest import MonkeyPatch
89
from yaml.constructor import ConstructorError
910

11+
import fmu.config as config
1012
from fmu.config import etc, utilities as util
1113
from fmu.config.configparserfmu import ConfigParserFMU
1214

@@ -144,3 +146,61 @@ def test_mapping_ordering_maintained(tmp_path: Path) -> None:
144146

145147
assert bad_cfg != cfg._config
146148
assert good_cfg == cfg._config
149+
150+
151+
def test_mapping_ordering_maintained_during_include(
152+
tmp_path: Path, monkeypatch: MonkeyPatch
153+
) -> None:
154+
monkeypatch.chdir(tmp_path)
155+
with open("global_config.yml", "w", encoding="utf-8") as f:
156+
# Can't yaml dump this, puts the !include in quotes
157+
f.write(
158+
"""
159+
revision: test
160+
global:
161+
foo: !include _bar.yml
162+
""".strip()
163+
)
164+
165+
_bar_yml = {
166+
"A_Upper": 11.2,
167+
"A_Lower_2": 12.3,
168+
"A_Lower_1": 12.3,
169+
"C_Fm_3": 13.4,
170+
"C_Fm_2": 13.4,
171+
"C_Fm_1": 13.4,
172+
"B_Upper_2": 14.5,
173+
"B_Upper_1": 14.5,
174+
"B_Lower_2": 14.3,
175+
"B_Lower_1": 14.3,
176+
}
177+
with open("_bar.yml", "w", encoding="utf-8") as f:
178+
f.write(yaml.dump(_bar_yml))
179+
180+
cfg = config.ConfigParserFMU()
181+
cfg.parse("global_config.yml")
182+
cfg.to_yaml(
183+
rootname="out_config",
184+
destination=tmp_path,
185+
template=tmp_path,
186+
)
187+
with open("out_config.yml", encoding="utf-8") as f:
188+
# Strip out added comments
189+
result = "".join([line for line in f.readlines() if not line.startswith("#")])
190+
191+
expected = """
192+
revision: test
193+
global:
194+
foo:
195+
A_Upper: 11.2
196+
A_Lower_2: 12.3
197+
A_Lower_1: 12.3
198+
C_Fm_3: 13.4
199+
C_Fm_2: 13.4
200+
C_Fm_1: 13.4
201+
B_Upper_2: 14.5
202+
B_Upper_1: 14.5
203+
B_Lower_2: 14.3
204+
B_Lower_1: 14.3
205+
""".strip()
206+
assert result.strip() == expected.strip()

0 commit comments

Comments
 (0)