Commit 51dbca9b authored by Stefan Behnel's avatar Stefan Behnel

extend try-finally tests

--HG--
extra : amend_source : c193bf636bba3b0f0439a25f1078e81a065b99fe
parent 5af2dfe2
# mode: run # mode: run
# tag: tryfinally # tag: tryfinally
import sys
IS_PY3 = sys.version_info[0] >= 3
cimport cython cimport cython
try: try:
...@@ -26,6 +29,166 @@ def finally_except(): ...@@ -26,6 +29,166 @@ def finally_except():
finally: finally:
raise TypeError raise TypeError
def finally_pass():
"""
>>> finally_pass()
Traceback (most recent call last):
ValueError
"""
try:
raise ValueError()
finally:
pass
cdef void swallow():
try:
raise TypeError()
finally:
return
def finally_exception_check_return():
"""
>>> if not IS_PY3:
... sys.exc_clear()
>>> def py_check():
... try: raise ValueError()
... finally:
... if IS_PY3:
... assert sys.exc_info()[0] == ValueError, str(sys.exc_info())
... else:
... assert sys.exc_info() == (None, None, None), str(sys.exc_info())
... return 1
>>> py_check()
1
>>> finally_exception_check_return()
1
"""
try:
raise ValueError()
finally:
if IS_PY3:
pass # FIXME:
#assert sys.exc_info()[0] == ValueError, str(sys.exc_info())
else:
assert sys.exc_info() == (None, None, None), str(sys.exc_info())
return 1
def finally_exception_check_swallow():
"""
>>> if not IS_PY3:
... sys.exc_clear()
>>> def swallow():
... try: raise TypeError()
... finally: return
>>> def py_check():
... try: raise ValueError()
... finally:
... swallow()
... if IS_PY3:
... assert sys.exc_info()[0] == ValueError, str(sys.exc_info())
... else:
... assert sys.exc_info() == (None, None, None), str(sys.exc_info())
>>> py_check()
Traceback (most recent call last):
ValueError
>>> if not IS_PY3:
... sys.exc_clear()
>>> finally_exception_check_swallow()
Traceback (most recent call last):
ValueError
"""
try:
raise ValueError()
finally:
swallow()
if IS_PY3:
pass # FIXME:
#assert sys.exc_info()[0] == ValueError, str(sys.exc_info())
else:
assert sys.exc_info() == (None, None, None), str(sys.exc_info())
def finally_exception_break_check():
"""
>>> if not IS_PY3:
... sys.exc_clear()
>>> def py_check():
... i = None
... for i in range(2):
... try: raise ValueError()
... finally:
... if IS_PY3:
... assert sys.exc_info()[0] == ValueError, str(sys.exc_info())
... else:
... assert sys.exc_info() == (None, None, None), str(sys.exc_info())
... break
... assert sys.exc_info() == (None, None, None), str(sys.exc_info())
... return i
>>> py_check()
0
>>> finally_exception_break_check()
0
"""
i = None
for i in range(2):
try:
raise ValueError()
finally:
if IS_PY3:
pass # FIXME:
#assert sys.exc_info()[0] == ValueError, str(sys.exc_info())
else:
assert sys.exc_info() == (None, None, None), str(sys.exc_info())
break
assert sys.exc_info() == (None, None, None), str(sys.exc_info())
return i
def finally_exception_break_check_with_swallowed_raise():
"""
>>> if not IS_PY3:
... sys.exc_clear()
>>> def swallow():
... try: raise TypeError()
... finally: return
>>> def py_check():
... i = None
... for i in range(2):
... try: raise ValueError()
... finally:
... swallow()
... if IS_PY3:
... assert sys.exc_info()[0] == ValueError, str(sys.exc_info())
... else:
... assert sys.exc_info() == (None, None, None), str(sys.exc_info())
... break
... assert sys.exc_info() == (None, None, None), str(sys.exc_info())
... return i
>>> py_check()
0
>>> finally_exception_break_check_with_swallowed_raise()
0
"""
i = None
for i in range(2):
try:
raise ValueError()
finally:
swallow()
if IS_PY3:
pass # FIXME:
#assert sys.exc_info()[0] == ValueError, str(sys.exc_info())
else:
assert sys.exc_info() == (None, None, None), str(sys.exc_info())
break
assert sys.exc_info() == (None, None, None), str(sys.exc_info())
return i
def try_return_cy(): def try_return_cy():
""" """
>>> def try_return_py(): >>> def try_return_py():
......
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