Skip to content
Snippets Groups Projects
Commit 1c9e8d88 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

more explicit error message for dgpy.plug argument issues

thanks @jviereck
parent 834ff2f5
No related branches found
No related tags found
No related merge requests found
...@@ -49,7 +49,8 @@ PyObject* plug( ...@@ -49,7 +49,8 @@ PyObject* plug(
if (signalIn == NULL) { if (signalIn == NULL) {
struct module_state* st = GETSTATE(m); struct module_state* st = GETSTATE(m);
std::ostringstream oss; std::ostringstream oss;
oss << "dgpy.plug in argument must be a dynamic_graph.Signal, not a " << PyCapsule_GetName(objIn); 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(st->dgpyError, oss.str().c_str());
return NULL; return NULL;
} }
...@@ -58,7 +59,8 @@ PyObject* plug( ...@@ -58,7 +59,8 @@ PyObject* plug(
if (signalOut == NULL) { if (signalOut == NULL) {
struct module_state* st = GETSTATE(m); struct module_state* st = GETSTATE(m);
std::ostringstream oss; std::ostringstream oss;
oss << "dgpy.plug out argument must be a dynamic_graph.Signal, not a " << PyCapsule_GetName(objOut); 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(st->dgpyError, oss.str().c_str());
return NULL; return NULL;
} }
......
...@@ -4,6 +4,8 @@ import dynamic_graph as dg ...@@ -4,6 +4,8 @@ import dynamic_graph as dg
from custom_entity import CustomEntity from custom_entity import CustomEntity
ERR = "dynamic_graph.plug(a, b): Argument '%s' must be of type 'dynamic_graph.Signal', but got dynamic_graph.Entity"
class BindingsTests(unittest.TestCase): class BindingsTests(unittest.TestCase):
def test_bindings(self): def test_bindings(self):
...@@ -20,14 +22,12 @@ class BindingsTests(unittest.TestCase): ...@@ -20,14 +22,12 @@ class BindingsTests(unittest.TestCase):
# Check that we can't connect first.out to second # Check that we can't connect first.out to second
with self.assertRaises(dg.dgpyError) as cm_in: with self.assertRaises(dg.dgpyError) as cm_in:
dg.plug(first.signal('out_double'), second) dg.plug(first.signal('out_double'), second)
self.assertEqual(str(cm_in.exception), self.assertEqual(str(cm_in.exception), ERR % 'b')
"dgpy.plug in argument must be a dynamic_graph.Signal, not a dynamic_graph.Entity")
# Check that we can't connect first to second.in # Check that we can't connect first to second.in
with self.assertRaises(dg.dgpyError) as cm_out: with self.assertRaises(dg.dgpyError) as cm_out:
dg.plug(first, second.signal('in_double')) dg.plug(first, second.signal('in_double'))
self.assertEqual(str(cm_out.exception), self.assertEqual(str(cm_out.exception), ERR % 'a')
"dgpy.plug out argument must be a dynamic_graph.Signal, not a dynamic_graph.Entity")
if __name__ == '__main__': if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment