Skip to content

Commit

Permalink
[thermo] Raise IndexError for invalid species index
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and speth committed Jan 18, 2021
1 parent a531922 commit 17b70eb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions interfaces/cython/cantera/test/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def test_species(self):
self.assertEqual(name, self.phase.species_name(i))
self.assertEqual(i, self.phase.species_index(name))
self.assertEqual(i, self.phase.species_index(i))
with self.assertRaisesRegex(ct.CanteraError, 'IndexError thrown by Phase::checkSpeciesIndex'):
self.phase.species(self.phase.n_species)

def test_elements(self):
self.assertEqual(self.phase.n_elements, 3)
Expand Down
1 change: 1 addition & 0 deletions src/thermo/Phase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,7 @@ shared_ptr<Species> Phase::species(const std::string& name) const

shared_ptr<Species> Phase::species(size_t k) const
{
checkSpeciesIndex(k);
return m_species.at(m_speciesNames[k]);
}

Expand Down

0 comments on commit 17b70eb

Please sign in to comment.