diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index 6dbf992d551..7294e201fa9 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -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": diff --git a/interfaces/cython/cantera/base.pyx b/interfaces/cython/cantera/base.pyx index d147980dcec..2816544d9ad 100644 --- a/interfaces/cython/cantera/base.pyx +++ b/interfaces/cython/cantera/base.pyx @@ -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): diff --git a/interfaces/cython/cantera/test/test_thermo.py b/interfaces/cython/cantera/test/test_thermo.py index 56a80b691f5..a59618dcd92 100644 --- a/interfaces/cython/cantera/test/test_thermo.py +++ b/interfaces/cython/cantera/test/test_thermo.py @@ -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)