Skip to content

Commit

Permalink
[ck2yaml] Raise the error when ck2yaml accidentally writes element
Browse files Browse the repository at this point in the history
symbol string which includes number in it, issue Cantera#853
  • Loading branch information
12Chao committed Jun 3, 2020
1 parent b23f184 commit 79fc57d
Show file tree
Hide file tree
Showing 4 changed files with 59,150 additions and 2 deletions.
10 changes: 9 additions & 1 deletion interfaces/cython/cantera/ck2yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,15 @@ def read_NASA7_entry(self, lines, TintDefault, comments):
if not composition:
raise InputError("Error parsing elemental composition for "
"species '{}'", species)

else:
for symbol in composition.keys():

# check if self.parse_composition parses composition correctly
if any(map(str.isdigit, symbol)) and symbol not in self.elements:
raise InputError("Error parsing elemental composition for "
"species thermo entry\n{}"
"\n the first line has an incorrect format", "".join(lines))

# Extract the NASA polynomial coefficients
# Remember that the high-T polynomial comes first!
Tmin = fortFloat(lines[0][45:55])
Expand Down
5 changes: 4 additions & 1 deletion interfaces/cython/cantera/test/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,10 @@ def test_extra(self):
self.assertEqual(desc, 'This is an alternative description.')
for key in ['foo', 'bar']:
self.assertIn(key, yml.keys())


def test_error_for_big_element_number(self):
with self.assertRaisesRegex(self.InputError, 'the first line has an incorrect format'):
self.convert('big_element_num_err.inp')

class CtmlConverterTest(utilities.CanteraTest):
def test_sofc(self):
Expand Down
Loading

0 comments on commit 79fc57d

Please sign in to comment.