Skip to content

Commit

Permalink
Merge pull request #27 from tnatt/yml-merge
Browse files Browse the repository at this point in the history
Allow for merge tags in yaml
  • Loading branch information
jcrivenaes authored Aug 10, 2020
2 parents 8961bfa + 0cc3a4a commit 394044e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/fmu/config/_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def construct_mapping(self, node, deep=False):
node.start_mark,
)

self.flatten_mapping(node)
mapping = OrderedDict()
for key_node, value_node in node.value:
key = self.construct_object(key_node, deep=deep)
Expand Down
23 changes: 23 additions & 0 deletions tests/data/yml/ogre/global_master_config_with_merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
global:
all_dates: &all_dates
DATES:
- 1991-07-01
- 2001-07-01
- 2003-07-01
DIFFDATES:
- [2001-07-01, 1991-07-01]
- [2003-07-01, 2001-07-01]
- [2005-07-01, 2003-07-01]
contacts: &contacts
FWL:
- 3953.0
- 3960.0
- 3957.0
GOC:
- 3943.0
- 3945.0
- 3942.0
rms:
<<: *contacts
<<: *all_dates

22 changes: 22 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
JFILE1 = "tests/data/yml/vinstre/global_master_config.yml"
TFILE2 = "tests/data/yml/ogre/global_master_config.yml"
TFILE3 = "tests/data/yml/ogre/global_master_config_with_dupl.yml"
TFILE4 = "tests/data/yml/ogre/global_master_config_with_merge.yml"
RFILE1 = "tests/data/yml/reek/global_variables.yml"

# result may be compared with data stored here
Expand Down Expand Up @@ -174,6 +175,27 @@ def test_to_yaml_ogre_selfread():
)


def test_ogre_to_yaml_merge():
"""Test the output for the YAML files, and convert OUTPUT yaml to ipl"""

cfg = config.ConfigParserFMU()

cfg.parse(TFILE4)
rootn = "ogre_yaml"

cfg.to_yaml(rootname=rootn, destination=fmux.tmpdir, template=fmux.tmpdir)

newinput = os.path.join(fmux.tmpdir, rootn + ".yml")
newrootn = "ogre_yaml_selfread"

cfx = config.ConfigParserFMU()
cfx.parse(newinput)

cfx.to_ipl(
rootname=newrootn, destination=fmux.tmpdir, template=fmux.tmpdir, tool="rms"
)


def test_yaml_has_duplicates_ogre():
"""The YAML file has duplicates; should raise error"""

Expand Down

0 comments on commit 394044e

Please sign in to comment.