Commit 3a89c5a0 authored by Vitja Makarov's avatar Vitja Makarov

add some more runtime tests for closures, nested functions and classes

parent 9bdf09cd
...@@ -72,3 +72,61 @@ def deleted(cond): ...@@ -72,3 +72,61 @@ def deleted(cond):
if cond: if cond:
del a del a
return a return a
def test_nested(cond):
"""
>>> test_nested(True)
<built-in function a>
>>> test_nested(False)
Traceback (most recent call last):
...
UnboundLocalError: a
"""
if cond:
def a():
pass
return a
def test_outer(cond):
"""
>>> test_outer(True)
{}
>>> test_outer(False)
Traceback (most recent call last):
...
UnboundLocalError: a
"""
if cond:
a = {}
def inner():
return a
return a
def test_inner(cond):
"""
>>> test_inner(True)
{}
>>> test_inner(False)
Traceback (most recent call last):
...
UnboundLocalError: a
"""
if cond:
a = {}
def inner():
return a
return inner()
def test_class(cond):
"""
>>> test_class(True) #doctest: +ELLIPSIS
<class uninitialized.A at 0x...>
>>> test_class(False)
Traceback (most recent call last):
...
UnboundLocalError: A
"""
if cond:
class A:
pass
return A
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