Skip to content

Commit

Permalink
[Input] Improve error message for missing phases key
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Jun 26, 2020
1 parent d321abe commit 40985bf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions interfaces/cython/cantera/_cantera.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ cdef extern from "cantera/base/AnyMap.h" namespace "Cantera":
cdef cppclass CxxAnyMap "Cantera::AnyMap":
CxxAnyMap()
CxxAnyValue& operator[](string) except +translate_exception
CxxAnyValue& at(string) except +translate_exception
string keys_str()

cdef cppclass CxxAnyValue "Cantera::AnyValue":
Expand Down
4 changes: 2 additions & 2 deletions interfaces/cython/cantera/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ cdef class _SolutionBase:
root = AnyMapFromYamlString(stringify(source))
self._source = 'custom YAML'

phaseNode = root[stringify("phases")].getMapWhere(stringify("name"),
stringify(name))
phaseNode = root.at(stringify("phases")).getMapWhere(stringify("name"),
stringify(name))

# Thermo
if isinstance(self, ThermoPhase):
Expand Down
16 changes: 16 additions & 0 deletions interfaces/cython/cantera/test/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ def setUp(self):
def test_source(self):
self.assertEqual(self.phase.source, 'h2o2.xml')

def test_missing_phases_key(self):
yaml = '''
species:
- name: H
composition: {H: 1}
thermo:
model: NASA7
temperature-ranges: [200.0, 1000.0, 6000.0]
data:
- [2.5, 0.0, 0.0, 0.0, 0.0, 2.547366e+04, -0.44668285]
- [2.5, 0.0, 0.0, 0.0, 0.0, 2.547366e+04, -0.44668285]
note: L6/94
'''
with self.assertRaisesRegex(ct.CanteraError, "Key 'phases' not found"):
_ = ct.Solution(yaml=yaml)

def test_base_attributes(self):
self.assertIsInstance(self.phase.name, str)
self.assertIsInstance(self.phase.phase_of_matter, str)
Expand Down

0 comments on commit 40985bf

Please sign in to comment.