Skip to content

Commit

Permalink
Preserve flow style when outputting user-defined fields
Browse files Browse the repository at this point in the history
  • Loading branch information
speth authored and ischoegl committed Jul 29, 2024
1 parent 75bb717 commit c86de9e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/base/AnyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ struct convert<Cantera::AnyMap> {

static bool decode(const Node& node, Cantera::AnyMap& target) {
target.setLoc(node.Mark().line, node.Mark().column);
if (node.Style() == YAML::EmitterStyle::Flow) {
target.setFlowStyle();
}
if (node.IsSequence()) {
// Convert a top-level list to a map with the key "items"
target["items"] = node.as<AnyValue>();
Expand Down
11 changes: 9 additions & 2 deletions test/python/test_composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import numpy as np
import pickle
import re

import pytest
from .utilities import allow_deprecated
Expand Down Expand Up @@ -1238,8 +1239,9 @@ def test_yaml_strings(self):
gas.species(3).update_user_data({"note": note3})
gas.species(4).update_user_data({"note": note4})

gas.write_yaml(self.test_work_path / "h2o2-generated-user-header.yaml")
gas2 = ct.Solution(self.test_work_path / "h2o2-generated-user-header.yaml")
generated_file = self.test_work_path / "h2o2-generated-user-header.yaml"
gas.write_yaml(generated_file)
gas2 = ct.Solution(generated_file)

# Ideally, multi-line YAML emitter would indicate stripping of the final newline
# (element annotated with '|-' instead of just '|') but this doesn't seem to be
Expand All @@ -1254,6 +1256,11 @@ def test_yaml_strings(self):
assert gas2.input_data["extra"]["key1"] == "1.0"
assert gas2.input_data["extra"]["key2"] == 2.0

# User-defined input in flow style should remain in flow style
yaml_gen = generated_file.read_text()
assert re.search("extra:.*key1.*key2", yaml_gen)


def test_duplicate_reactions(self):
gas = ct.Solution('h2o2.yaml', transport_model=None)

Expand Down

0 comments on commit c86de9e

Please sign in to comment.