Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
51dbca9b
Commit
51dbca9b
authored
Dec 28, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extend try-finally tests
--HG-- extra : amend_source : c193bf636bba3b0f0439a25f1078e81a065b99fe
parent
5af2dfe2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
163 additions
and
0 deletions
+163
-0
tests/run/tryfinally.pyx
tests/run/tryfinally.pyx
+163
-0
No files found.
tests/run/tryfinally.pyx
View file @
51dbca9b
# mode: run
# tag: tryfinally
import
sys
IS_PY3
=
sys
.
version_info
[
0
]
>=
3
cimport
cython
try
:
...
...
@@ -26,6 +29,166 @@ def finally_except():
finally
:
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_py():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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