test_bindings.py
Go to the documentation of this file.
1 import unittest
2 
3 import dynamic_graph as dg
4 from custom_entity import CustomEntity
5 
6 ERR = (
7  """Python argument types in
8  dynamic_graph.wrap.plug(%s, %s)
9 did not match C++ signature:
10  plug("""
11  "dynamicgraph::SignalBase<long>* signalOut, "
12  "dynamicgraph::SignalBase<long>* signalIn)"
13 )
14 
15 
16 class BindingsTests(unittest.TestCase):
17  def test_type_check(self):
18  """
19  test the type checking in signal plugs
20  """
21  first = CustomEntity("first_entity")
22  second = CustomEntity("second_entity")
23  # Check that we can connect first.out to second.in
24  dg.plug(first.signal("out_double"), second.signal("in_double"))
25 
26  # Check that we can't connect first.out to second
27  with self.assertRaises(TypeError) as cm_in:
28  dg.plug(first.signal("out_double"), second)
29  self.assertEqual(
30  str(cm_in.exception), ERR % ("SignalTimeDependentDouble", "CustomEntity")
31  )
32 
33  # Check that we can't connect first to second.in
34  with self.assertRaises(TypeError) as cm_out:
35  dg.plug(first, second.signal("in_double"))
36  self.assertEqual(
37  str(cm_out.exception), ERR % ("CustomEntity", "SignalPtrDouble")
38  )
39 
40  def test_dg_exc(self):
41  """
42  test that exceptions from dynamic graph are correctly raised
43  """
44  ent = CustomEntity("test_dg_exc")
45  # check that accessing a non initialized signal raises
46  with self.assertRaises(RuntimeError) as cm:
47  ent.act()
48  self.assertEqual(
49  str(cm.exception),
50  "In SignalPtr: SIN ptr not set. "
51  "(in signal <CustomEntity(test_dg_exc)::input(double)::in_double>)",
52  )
53 
54  # check that accessing an initialized signal doesn't raise
55  ent_2 = CustomEntity("another_entity")
56  dg.plug(ent_2.signal("out_double"), ent.signal("in_double"))
57  ent.act()
58 
59 
60 if __name__ == "__main__":
61  unittest.main()
test_bindings.BindingsTests.test_dg_exc
def test_dg_exc(self)
Definition: test_bindings.py:40
test_bindings.BindingsTests.test_type_check
def test_type_check(self)
Definition: test_bindings.py:17
test_bindings.BindingsTests
Definition: test_bindings.py:16


dynamic-graph-python
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Fri Oct 27 2023 02:16:36