Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
mantidproject
mantid
Commits
4bf44c28
Commit
4bf44c28
authored
Sep 15, 2021
by
Jose Borreguero
Browse files
overload get method
Signed-off-by:
Jose Borreguero
<
borreguero@gmail.com
>
parent
1b5f3637
Changes
2
Hide whitespace changes
Inline
Side-by-side
Framework/PythonInterface/mantid/kernel/src/Exports/ConfigService.cpp
View file @
4bf44c28
...
...
@@ -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
);
else
return
defaultValue
;
return
value
;
}
GNU_DIAG_OFF
(
"unused-local-typedef"
)
...
...
@@ -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"
)))
...
...
Framework/PythonInterface/test/python/mantid/kernel/ConfigServiceTest.py
View file @
4bf44c28
...
...
@@ -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"
self
.
assertTrue
(
config
.
hasProperty
(
test_prop
))
dictcall
=
config
[
test_prop
]
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment