Commit 6ff7168c authored by Guilhem Saurel's avatar Guilhem Saurel

raise TypeError instead of dgpyError in dg.plug

As, from the docs:
> Passing arguments of the wrong type (e.g. passing a list when an int
> is expected) should result in a TypeError.

Thanks @jmirabel
parent 1c9e8d88
......@@ -17,13 +17,7 @@ namespace python {
/**
\brief plug a signal into another one.
*/
PyObject* plug(
#if PY_MAJOR_VERSION >= 3
PyObject* m, PyObject* args
#else
PyObject*, PyObject* args
#endif
) {
PyObject* plug(PyObject* /*self*/, PyObject* args) {
PyObject* objOut = NULL;
PyObject* objIn = NULL;
void* pObjOut;
......@@ -47,21 +41,19 @@ PyObject* plug(
pObjIn = PyCapsule_GetPointer(objIn, "dynamic_graph.Signal");
SignalBase<int>* signalIn = (SignalBase<int>*)pObjIn;
if (signalIn == NULL) {
struct module_state* st = GETSTATE(m);
std::ostringstream oss;
oss << "dynamic_graph.plug(a, b): Argument 'b' must be of type 'dynamic_graph.Signal', but got "
<< PyCapsule_GetName(objIn);
PyErr_SetString(st->dgpyError, oss.str().c_str());
PyErr_SetString(PyExc_TypeError, oss.str().c_str());
return NULL;
}
pObjOut = PyCapsule_GetPointer(objOut, "dynamic_graph.Signal");
SignalBase<int>* signalOut = (SignalBase<int>*)pObjOut;
if (signalOut == NULL) {
struct module_state* st = GETSTATE(m);
std::ostringstream oss;
oss << "dynamic_graph.plug(a, b): Argument 'a' must be of type 'dynamic_graph.Signal', but got "
<< PyCapsule_GetName(objOut);
PyErr_SetString(st->dgpyError, oss.str().c_str());
PyErr_SetString(PyExc_TypeError, oss.str().c_str());
return NULL;
}
std::ostringstream os;
......
......@@ -20,12 +20,12 @@ class BindingsTests(unittest.TestCase):
dg.plug(first.signal('out_double'), second.signal('in_double'))
# Check that we can't connect first.out to second
with self.assertRaises(dg.dgpyError) as cm_in:
with self.assertRaises(TypeError) as cm_in:
dg.plug(first.signal('out_double'), second)
self.assertEqual(str(cm_in.exception), ERR % 'b')
# Check that we can't connect first to second.in
with self.assertRaises(dg.dgpyError) as cm_out:
with self.assertRaises(TypeError) as cm_out:
dg.plug(first, second.signal('in_double'))
self.assertEqual(str(cm_out.exception), ERR % 'a')
......
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