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

Commit 8ee7e43

Browse files
committed
check signal types in dg.plug
While here, develop test from previous commit, and fix another test in the same file. fix #36
1 parent 6e43bd1 commit 8ee7e43

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
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/test_bindings.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66

77
class BindingsTests(unittest.TestCase):
88
def test_bindings(self):
9-
with self.assertRaises(Exception) as error:
9+
with self.assertRaises(Exception) as cm:
1010
dg.error_out()
11-
self.assertEqual(str(error), "something bad happend")
11+
self.assertEqual(str(cm.exception), "something bad happened")
1212

1313
def test_type_check(self):
1414
first = CustomEntity('first_entity')
1515
second = CustomEntity('second_entity')
1616
# Check that we can connect first.out to second.in
1717
dg.plug(first.signal('out_double'), second.signal('in_double'))
1818
# Check that we can't connect first.out to second
19-
with self.assertRaises(Exception):
19+
with self.assertRaises(ValueError) as cm:
2020
dg.plug(first.signal('out_double'), second)
21+
self.assertEqual(str(cm.exception), "PyCapsule_GetPointer called with incorrect name")
2122

2223

2324
if __name__ == '__main__':

0 commit comments

Comments
 (0)