Commit 4bf44c28 authored by Jose Borreguero's avatar Jose Borreguero
Browse files

overload get method

Signed-off-by: default avatarJose Borreguero <>
parent 1b5f3637
......@@ -53,10 +53,11 @@ const InstrumentInfo &getInstrument(ConfigServiceImpl &self, const object &name
/// duck typing emulating dict.get method
std::string getStringUsingCacheElseDefault(ConfigServiceImpl &self, const std::string &key,
const std::string &defaultValue) {
std::string value = self.getString(key, true);
if (value.empty())
std::vector<std::string> keys = self.keys();
if (std::find(keys.begin(), keys.end(), key) != keys.end())
return self.getString(key, true);
return defaultValue;
return value;
......@@ -143,6 +144,7 @@ void export_ConfigService() {
.def("keys", &ConfigServiceImpl::keys, arg("self"))
// Treat this as a dictionary
.def("get", &getStringUsingCache, (arg("self"), arg("key")))
.def("get", &getStringUsingCacheElseDefault, (arg("self"), arg("key")), arg("default"),
"get the value of a property; return a default value if the property is not found in the configuration")
.def("__getitem__", &getStringUsingCache, (arg("self"), arg("key")))
......@@ -64,6 +64,9 @@ class ConfigServiceTest(unittest.TestCase):
self.assertRaises(RuntimeError, config.getInstrument, "MadeUpInstrument")
def test_service_acts_like_dictionary(self):
dictcall = config.get("property_not_found")
self.assertEqual(dictcall, "")
test_prop = "projectRecovery.secondsBetween"
dictcall = config[test_prop]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment