Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit f874f72

Browse files
authored
Merge pull request #37 from nim65s/devel
check signal types in dg.plug, fix #36
2 parents 4db3057 + 8ee7e43 commit f874f72

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/dynamic_graph/dynamic-graph-py.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ PyObject* plug(PyObject* /*self*/, PyObject* args) {
4040

4141
pObjIn = PyCapsule_GetPointer(objIn, "dynamic_graph.Signal");
4242
SignalBase<int>* signalIn = (SignalBase<int>*)pObjIn;
43+
if (signalIn == NULL) return NULL;
4344
pObjOut = PyCapsule_GetPointer(objOut, "dynamic_graph.Signal");
4445
SignalBase<int>* signalOut = (SignalBase<int>*)pObjOut;
46+
if (signalOut == NULL) return NULL;
4547
std::ostringstream os;
4648

4749
try {

unitTesting/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Test bindings
2-
ADD_PYTHON_UNIT_TEST("test-bindings" "unitTesting/test_bindings.py" src)
31

42
# Test the interpreter
53
SET(EXECUTABLE_NAME interpreter-test)
@@ -59,3 +57,6 @@ TARGET_LINK_LIBRARIES(${PYTHON_MODULE} ${PUBLIC_KEYWORD} ${LIBRARY_NAME} ${PYTHO
5957

6058
## Test it
6159
ADD_PYTHON_UNIT_TEST("test-custom-entity" "unitTesting/test_custom_entity.py" src unitTesting)
60+
61+
# also test other bindings, using this custom entity
62+
ADD_PYTHON_UNIT_TEST("test-bindings" "unitTesting/test_bindings.py" src unitTesting)

unitTesting/test_bindings.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
import unittest
22

3-
import dynamic_graph
3+
import dynamic_graph as dg
4+
from custom_entity import CustomEntity
45

56

67
class BindingsTests(unittest.TestCase):
78
def test_bindings(self):
8-
with self.assertRaises(Exception) as error:
9-
dynamic_graph.error_out()
10-
self.assertEqual(str(error), "something bad happend")
9+
with self.assertRaises(Exception) as cm:
10+
dg.error_out()
11+
self.assertEqual(str(cm.exception), "something bad happened")
12+
13+
def test_type_check(self):
14+
first = CustomEntity('first_entity')
15+
second = CustomEntity('second_entity')
16+
# Check that we can connect first.out to second.in
17+
dg.plug(first.signal('out_double'), second.signal('in_double'))
18+
# Check that we can't connect first.out to second
19+
with self.assertRaises(ValueError) as cm:
20+
dg.plug(first.signal('out_double'), second)
21+
self.assertEqual(str(cm.exception), "PyCapsule_GetPointer called with incorrect name")
1122

1223

1324
if __name__ == '__main__':

0 commit comments

Comments
 (0)