Author: Antonio Cuni <[email protected]>
Branch: py3k
Changeset: r51757:4df3b47d0b13
Date: 2012-01-25 10:17 +0100
http://bitbucket.org/pypy/pypy/changeset/4df3b47d0b13/
Log: add more tests about the nonlocal declaration introduced by
d6d9ea7ba306
diff --git a/pypy/interpreter/astcompiler/test/test_symtable.py
b/pypy/interpreter/astcompiler/test/test_symtable.py
--- a/pypy/interpreter/astcompiler/test/test_symtable.py
+++ b/pypy/interpreter/astcompiler/test/test_symtable.py
@@ -274,6 +274,34 @@
exc = py.test.raises(SyntaxError, self.func_scope, input).value
assert exc.msg == "name 'x' is parameter and global"
+ def test_nonlocal(self):
+ src = str(py.code.Source("""
+ def f():
+ nonlocal x
+ global x
+ """))
+ exc = py.test.raises(SyntaxError, self.func_scope, src).value
+ assert exc.msg == "name 'x' is nonlocal and global"
+ #
+ src = str(py.code.Source("""
+ def f(x):
+ nonlocal x
+ """))
+ exc = py.test.raises(SyntaxError, self.func_scope, src).value
+ assert exc.msg == "name 'x' is parameter and nonlocal"
+ #
+ src = str(py.code.Source("""
+ def f():
+ nonlocal x
+ """))
+ exc = py.test.raises(SyntaxError, self.func_scope, src).value
+ assert exc.msg == "no binding for nonlocal 'x' found"
+ #
+ src = "nonlocal x"
+ exc = py.test.raises(SyntaxError, self.func_scope, src).value
+ assert exc.msg == "nonlocal declaration not allowed at module level"
+
+
def test_optimization(self):
assert not self.mod_scope("").can_be_optimized
assert not self.class_scope("class x: pass").can_be_optimized
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit