Commit 7dc6728c authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

[Tests] add test_dg_exc

This adds a command in Custom Entity that acts on the input signal.
Acting on this input signal before setting it should raise an exception
from dynamic-graph.

test_dg_exc was added to check that, and fails for now.


While here, fix exception type check in test_bindings.
parent 63d0a6ef
......@@ -8,11 +8,12 @@
#include <sstream>
#include <dynamic-graph/entity.h>
#include <dynamic-graph/exception-factory.h>
#include "dynamic-graph/factory.h"
#include "dynamic-graph/pool.h"
#include <dynamic-graph/factory.h>
#include <dynamic-graph/pool.h>
#include <dynamic-graph/real-time-logger.h>
#include <dynamic-graph/signal-ptr.h>
#include <dynamic-graph/signal-time-dependent.h>
#include <dynamic-graph/command-bind.h>
namespace dynamicgraph {
class CustomEntity : public Entity {
......@@ -30,6 +31,11 @@ class CustomEntity : public Entity {
using namespace dynamicgraph::command;
this->addCommand("act", makeCommandVoid0( *this, &CustomEntity::act,
docCommandVoid0( "act on input signal")));
void addSignal() { signalRegistration(m_sigdSIN << m_sigdTimeDepSOUT); }
......@@ -56,6 +62,10 @@ class CustomEntity : public Entity {
sendMsg("end update", MSG_TYPE_ERROR, __FILE__, __LINE__);
return res;
void act() {
} // namespace dynamicgraph
......@@ -9,11 +9,14 @@ ERR = "dynamic_graph.plug(a, b): Argument '%s' must be of type 'dynamic_graph.Si
class BindingsTests(unittest.TestCase):
def test_bindings(self):
with self.assertRaises(Exception) as cm:
with self.assertRaises(dg.dgpyError) as cm:
self.assertEqual(str(cm.exception), "something bad happened")
def test_type_check(self):
test the type checking in signal plugs
first = CustomEntity('first_entity')
second = CustomEntity('second_entity')
# Check that we can connect first.out to
......@@ -29,6 +32,23 @@ class BindingsTests(unittest.TestCase):
dg.plug(first, second.signal('in_double'))
self.assertEqual(str(cm_out.exception), ERR % 'a')
def test_dg_exc(self):
test that exceptions from dynamic graph are correctly raised
ent = CustomEntity('test_dg_exc')
# check that accessing a non initialized signal raises
with self.assertRaises(dg.dgpyError) as cm:
'In SignalPtr: SIN ptr not set. (in signal <CustomEntity(test_dg_exc)::input(double)::in_double>)')
# check that accessing an initialized signal doesn't raise
ent_2 = CustomEntity('another_entity')
dg.plug(ent_2.signal('out_double'), ent.signal('in_double'))
if __name__ == '__main__':
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