Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ doc/ctdeploy_key
*.exe.manifest
build/
test/work/
test_problems/ChemEquil_ionizedGas/ChemEquil_ionizedGas
test_problems/cathermo/testWaterPDSS/WaterPDSS
test_problems/cathermo/testWaterTP/WaterSSTP
test_problems/cxx_ex/cxx_ex
test_problems/diamondSurf/diamondSurf
test_problems/pureFluidTest/pureFluid
test_problems/rankine_democxx/rankine_democxx
test_problems/surfkin/surfkin
interfaces/cython/cantera/_cantera.h
include/cantera/base/config.h
include/cantera/base/config.h.build
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
6 changes: 6 additions & 0 deletions src/base/AnyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,9 @@ const AnyMap& AnyValue::getMapWhere(const std::string& key, const std::string& v
throw InputFileError("AnyValue::getMapWhere", *this,
"Map does not contain a key where '{}' = '{}'", key, value);
}
} else if (is<void>()) {
throw InputFileError("AnyValue::getMapWhere", *this,
"Key '{}' not found", m_key);
} else {
throw InputFileError("AnyValue::getMapWhere", *this,
"Element is not a mapping or list of mappings");
Expand Down Expand Up @@ -703,6 +706,9 @@ AnyMap& AnyValue::getMapWhere(const std::string& key, const std::string& value,
child[key] = value;
operator=(std::move(child));
return as<AnyMap>();
} else if (is<void>()) {
throw InputFileError("AnyValue::getMapWhere", *this,
"Key '{}' not found", m_key);
} else {
throw InputFileError("AnyValue::getMapWhere", *this,
"Element is not a mapping or list of mappings");
Expand Down
21 changes: 21 additions & 0 deletions test/general/test_containers.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "cantera/base/AnyMap.h"

using namespace Cantera;
Expand Down Expand Up @@ -322,6 +323,26 @@ TEST(AnyMap, loadYaml)
EXPECT_DOUBLE_EQ(coeffs[1][2], -8.280690600E-07);
}

TEST(AnyMap, missingKey)
{
AnyMap root = AnyMap::fromYamlFile("ideal-gas.yaml");
try {
root["spam"].getMapWhere("name", "unknown");
} catch (std::exception& ex) {
EXPECT_THAT(ex.what(), ::testing::HasSubstr("Key 'spam' not found"));
}
}

TEST(AnyMap, missingKeyAt)
{
AnyMap root = AnyMap::fromYamlFile("ideal-gas.yaml");
try {
root.at("spam").getMapWhere("name", "unknown");
} catch (std::exception& ex) {
EXPECT_THAT(ex.what(), ::testing::HasSubstr("Key 'spam' not found"));
}
}

TEST(AnyMap, loadDeprecatedYaml)
{
// The deprecation warning in this file is turned into an
Expand Down