Commit a1a9de10 authored by David Fairbrother's avatar David Fairbrother Committed by Gemma Guest
Browse files

Reject duplicated args and kwargs in CreateChildAlg

Rejects a duplicated kwargs and arg, as boost used to handle this before
we took over parsing manually using raw functions.
Now we will explicitly check for this, and throw a invalid_exception (we
couldn't find something for a TypeError though, so there is a potential
future improvement)
parent 0a12a4a4
......@@ -98,9 +98,15 @@ template <typename T> boost::optional<T> extractArg(ssize_t index, const tuple &
template <typename T> void extractKwargs(const dict &kwargs, const std::string &keyName, boost::optional<T> &out) {
if (kwargs.has_key(keyName)) {
out = boost::optional<T>(extract<T>(kwargs.get(keyName)));
if (!kwargs.has_key(keyName)) {
if (out != boost::none) {
throw std::invalid_argument("Parameter called '" + keyName +
"' was specified twice."
" This must be either positional or a kwarg, but not both.");
out = boost::optional<T>(extract<T>(kwargs.get(keyName)));
class SetPropertyVisitor final : public Mantid::PythonInterface::IPyTypeVisitor {
......@@ -267,6 +267,17 @@ class AlgorithmTest(unittest.TestCase):
child_alg = parent_alg.createChildAlgorithm("_ParamTester", **args)
def test_name_provided_as_arg_and_kwarg_throws(self):
parent_alg = AlgorithmManager.createUnmanaged('Load')
args = {"name": "CreateSampleWorkspace"}
with self.assertRaisesRegex(ValueError, "was specified twice"):
parent_alg.createChildAlgorithm("_ParamTester", **args)
def test_name_provided_as_kwarg_twice_throws(self):
parent_alg = AlgorithmManager.createUnmanaged('Load')
args = {"name": "CreateSampleWorkspace"}
with self.assertRaises(TypeError):
parent_alg.createChildAlgorithm(name="_ParamTester", **args)
if __name__ == '__main__':
Markdown is supported
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