Commit 36f86e49 authored by Stefan Behnel's avatar Stefan Behnel

move doctests into tested functions

parent 848176a5
__doc__ = u""" # mode: run
>>> try: # tag: tryfinally
... raise ValueError
... finally:
... raise TypeError
Traceback (most recent call last):
TypeError
>>> finally_except()
Traceback (most recent call last):
TypeError
>>> call_try_return_with_exception()
1
>>> def try_return_py():
... try:
... return 1
... finally:
... return 2
>>> try_return_py()
2
>>> try_return_cy()
2
>>> call_try_return_c()
2
>>> i=1
>>> for i in range(3):
... try:
... continue
... finally:
... i+=1
>>> i
3
>>> try_continue(3)
3
>>> try_return_none_1()
>>> try_return_none_2()
>>> try_break()
"""
def finally_except(): def finally_except():
"""
>>> try:
... raise ValueError
... finally:
... raise TypeError
Traceback (most recent call last):
TypeError
>>> finally_except()
Traceback (most recent call last):
TypeError
"""
try: try:
raise ValueError raise ValueError
finally: finally:
raise TypeError raise TypeError
def try_return_cy(): def try_return_cy():
"""
>>> def try_return_py():
... try:
... return 1
... finally:
... return 2
>>> try_return_py()
2
>>> try_return_cy()
2
"""
try: try:
return 1 return 1
finally: finally:
...@@ -58,6 +42,10 @@ cdef int try_return_c(): ...@@ -58,6 +42,10 @@ cdef int try_return_c():
return 2 return 2
def call_try_return_c(): def call_try_return_c():
"""
>>> call_try_return_c()
2
"""
return try_return_c() return try_return_c()
cdef int try_return_with_exception(): cdef int try_return_with_exception():
...@@ -67,6 +55,10 @@ cdef int try_return_with_exception(): ...@@ -67,6 +55,10 @@ cdef int try_return_with_exception():
return 1 return 1
def call_try_return_with_exception(): def call_try_return_with_exception():
"""
>>> call_try_return_with_exception()
1
"""
return try_return_with_exception() return try_return_with_exception()
def try_return_temp(a): def try_return_temp(a):
...@@ -78,6 +70,18 @@ def try_return_temp(a): ...@@ -78,6 +70,18 @@ def try_return_temp(a):
print b-a print b-a
def try_continue(a): def try_continue(a):
"""
>>> i=1
>>> for i in range(3):
... try:
... continue
... finally:
... i+=1
>>> i
3
>>> try_continue(3)
3
"""
i=1 i=1
for i in range(a): for i in range(a):
try: try:
...@@ -88,6 +92,9 @@ def try_continue(a): ...@@ -88,6 +92,9 @@ def try_continue(a):
def try_return_none_1(): def try_return_none_1():
"""
>>> try_return_none_1()
"""
try: try:
return return
finally: finally:
...@@ -103,12 +110,18 @@ cdef PyObject* _none(): ...@@ -103,12 +110,18 @@ cdef PyObject* _none():
return <PyObject*> ret return <PyObject*> ret
def try_return_none_2(): def try_return_none_2():
"""
>>> try_return_none_2()
"""
try: try:
return <object> _none() return <object> _none()
finally: finally:
return <object> _none() return <object> _none()
def try_break(): def try_break():
"""
>>> try_break()
"""
for a in "abcd": for a in "abcd":
try: try:
if a == 'c': if a == 'c':
......
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