Commit 50f00cf8 authored by Stefan Behnel's avatar Stefan Behnel

Add tests that exception propagation works with the "@returns()" decorator.

parent 95bad952
...@@ -217,6 +217,8 @@ def test_declare_c_types(n): ...@@ -217,6 +217,8 @@ def test_declare_c_types(n):
@cython.ccall @cython.ccall
@cython.returns(cython.double) @cython.returns(cython.double)
def c_call(x): def c_call(x):
if x == -2.0:
raise RuntimeError("huhu!")
return x return x
...@@ -235,6 +237,10 @@ def call_ccall(x): ...@@ -235,6 +237,10 @@ def call_ccall(x):
1.0 1.0
>>> (is_compiled and 1) or result >>> (is_compiled and 1) or result
1 1
>>> call_ccall(-2)
Traceback (most recent call last):
RuntimeError: huhu!
""" """
ret = c_call(x) ret = c_call(x)
return ret, cython.typeof(ret) return ret, cython.typeof(ret)
...@@ -244,6 +250,8 @@ def call_ccall(x): ...@@ -244,6 +250,8 @@ def call_ccall(x):
@cython.inline @cython.inline
@cython.returns(cython.double) @cython.returns(cython.double)
def cdef_inline(x): def cdef_inline(x):
if x == -2.0:
raise RuntimeError("huhu!")
return x + 1 return x + 1
...@@ -258,6 +266,10 @@ def call_cdef_inline(x): ...@@ -258,6 +266,10 @@ def call_cdef_inline(x):
'int' 'int'
>>> result == 2.0 or result >>> result == 2.0 or result
True True
>>> call_cdef_inline(-2)
Traceback (most recent call last):
RuntimeError: huhu!
""" """
ret = cdef_inline(x) ret = cdef_inline(x)
return ret, cython.typeof(ret) return ret, cython.typeof(ret)
...@@ -392,6 +404,23 @@ def ccall_except_check_always(x): ...@@ -392,6 +404,23 @@ def ccall_except_check_always(x):
return x+1 return x+1
@cython.test_fail_if_path_exists("//CFuncDeclaratorNode//IntNode[@value = '-1']")
@cython.test_assert_path_exists("//CFuncDeclaratorNode")
@cython.ccall
@cython.returns(cython.long)
@cython.exceptval(check=False)
def ccall_except_no_check(x):
"""
>>> ccall_except_no_check(41)
42
>>> try: _ = ccall_except_no_check(0) # no exception propagated!
... except ValueError: assert not is_compiled
"""
if x == 0:
raise ValueError
return x+1
@cython.final @cython.final
@cython.cclass @cython.cclass
class CClass(object): class CClass(object):
......
Markdown is supported
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