Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stack Of Tasks
dynamic-graph-python
Commits
63d0a6ef
Unverified
Commit
63d0a6ef
authored
Dec 05, 2019
by
Guilhem Saurel
Committed by
GitHub
Dec 05, 2019
Browse files
Merge pull request #38 from nim65s/devel
explicit error in case of misuse of dg.plug, fix #36
parents
f874f72c
6ff7168c
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/dynamic_graph/dynamic-graph-py.cc
View file @
63d0a6ef
...
...
@@ -40,10 +40,22 @@ PyObject* plug(PyObject* /*self*/, PyObject* args) {
pObjIn
=
PyCapsule_GetPointer
(
objIn
,
"dynamic_graph.Signal"
);
SignalBase
<
int
>*
signalIn
=
(
SignalBase
<
int
>*
)
pObjIn
;
if
(
signalIn
==
NULL
)
return
NULL
;
if
(
signalIn
==
NULL
)
{
std
::
ostringstream
oss
;
oss
<<
"dynamic_graph.plug(a, b): Argument 'b' must be of type 'dynamic_graph.Signal', but got "
<<
PyCapsule_GetName
(
objIn
);
PyErr_SetString
(
PyExc_TypeError
,
oss
.
str
().
c_str
());
return
NULL
;
}
pObjOut
=
PyCapsule_GetPointer
(
objOut
,
"dynamic_graph.Signal"
);
SignalBase
<
int
>*
signalOut
=
(
SignalBase
<
int
>*
)
pObjOut
;
if
(
signalOut
==
NULL
)
return
NULL
;
if
(
signalOut
==
NULL
)
{
std
::
ostringstream
oss
;
oss
<<
"dynamic_graph.plug(a, b): Argument 'a' must be of type 'dynamic_graph.Signal', but got "
<<
PyCapsule_GetName
(
objOut
);
PyErr_SetString
(
PyExc_TypeError
,
oss
.
str
().
c_str
());
return
NULL
;
}
std
::
ostringstream
os
;
try
{
...
...
@@ -123,6 +135,14 @@ void initwrap(void)
INITERROR
;
}
Py_XINCREF
(
st
->
dgpyError
);
if
(
PyModule_AddObject
(
module
,
"dgpyError"
,
st
->
dgpyError
)
<
0
)
{
Py_XDECREF
(
st
->
dgpyError
);
Py_CLEAR
(
st
->
dgpyError
);
Py_DECREF
(
module
);
return
NULL
;
}
#if PY_MAJOR_VERSION >= 3
return
module
;
#endif
...
...
unitTesting/interpreter-test-runfile.cc
View file @
63d0a6ef
...
...
@@ -62,7 +62,11 @@ int main(int argc, char** argv) {
res
=
testFile
(
"test_python-syntax_error.py"
,
std
::
string
(
" File
\"
test_python-syntax_error.py
\"
, line 2
\n
"
" hello world
\n
"
#if PY_MINOR_VERSION >= 8
" ^
\n
"
#else
" ^
\n
"
#endif
"SyntaxError: invalid syntax
\n
"
),
numTest
)
&&
res
;
...
...
unitTesting/test_bindings.py
View file @
63d0a6ef
import
unittest
import
dynamic_graph
as
dg
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
):
def
test_bindings
(
self
):
...
...
@@ -15,10 +18,16 @@ class BindingsTests(unittest.TestCase):
second
=
CustomEntity
(
'second_entity'
)
# Check that we can connect first.out to second.in
dg
.
plug
(
first
.
signal
(
'out_double'
),
second
.
signal
(
'in_double'
))
# Check that we can't connect first.out to second
with
self
.
assertRaises
(
Valu
eError
)
as
cm
:
with
self
.
assertRaises
(
Typ
eError
)
as
cm
_in
:
dg
.
plug
(
first
.
signal
(
'out_double'
),
second
)
self
.
assertEqual
(
str
(
cm
.
exception
),
"PyCapsule_GetPointer called with incorrect name"
)
self
.
assertEqual
(
str
(
cm_in
.
exception
),
ERR
%
'b'
)
# Check that we can't connect first to second.in
with
self
.
assertRaises
(
TypeError
)
as
cm_out
:
dg
.
plug
(
first
,
second
.
signal
(
'in_double'
))
self
.
assertEqual
(
str
(
cm_out
.
exception
),
ERR
%
'a'
)
if
__name__
==
'__main__'
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment