Skip to content

Commit

Permalink
[YAML] Append rather than replace extra description
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Feb 10, 2020
1 parent 40629d9 commit 6cc6b7b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 5 additions & 3 deletions interfaces/cython/cantera/ck2yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
is used to override default phase names (i.e. 'gas').
The '--extra=<filename>' option takes a YAML file as input. This option can be
used to specify an alternative file description, or to define custom fields that
are included in the YAML output.
used to add to the file description, or to define custom fields that are
included in the YAML output.
"""

from collections import defaultdict, OrderedDict
Expand Down Expand Up @@ -1355,7 +1355,9 @@ def load_extra_file(self, path):
# replace header lines
if 'description' in yml:
if isinstance(yml['description'], str):
self.header_lines = yml.pop('description').split('\n')
if self.header_lines:
self.header_lines += ['']
self.header_lines += yml.pop('description').split('\n')
else:
raise InputError("The alternate description provided in "
"'{}' needs to be a string".format(path))
Expand Down
5 changes: 2 additions & 3 deletions interfaces/cython/cantera/test/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,8 @@ def test_extra(self):
with open(output, 'rt', encoding="utf-8") as stream:
yml = yaml.safe_load(stream)

desc = yml['description']
self.assertEqual(yml['description'],
'This is an alternative description.')
desc = yml['description'].split()[-1]
self.assertEqual(desc, 'This is an alternative description.')
for key in ['foo', 'bar']:
self.assertIn(key, yml.keys())

Expand Down

0 comments on commit 6cc6b7b

Please sign in to comment.