summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_scope.py
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2001-03-21 16:44:39 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2001-03-21 16:44:39 (GMT)
commit5c7a2513ec277c6c4f5ab4f44b461aeb17a850c4 (patch)
treef1df576a88b5bebe26d5fd50f7c0d77c19092363 /Lib/test/test_scope.py
parent220ae7c0bf2054ad01f58e1cf669ac069eb9a574 (diff)
downloadcpython-5c7a2513ec277c6c4f5ab4f44b461aeb17a850c4.zip
cpython-5c7a2513ec277c6c4f5ab4f44b461aeb17a850c4.tar.gz
cpython-5c7a2513ec277c6c4f5ab4f44b461aeb17a850c4.tar.bz2
Add tests for recent changes:
- global stmt in class does not affect free vars in methods - locals() works with free and cell vars
Diffstat (limited to 'Lib/test/test_scope.py')
-rw-r--r--Lib/test/test_scope.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_scope.py b/Lib/test/test_scope.py
index 5df0328..d6367b2 100644
--- a/Lib/test/test_scope.py
+++ b/Lib/test/test_scope.py
@@ -405,3 +405,33 @@ for i in range(100):
f1()
verify(Foo.count == 0)
+
+print "17. class and global"
+
+def test(x):
+ class Foo:
+ global x
+ def __call__(self, y):
+ return x + y
+ return Foo()
+
+x = 0
+verify(test(6)(2) == 8)
+x = -1
+verify(test(3)(2) == 5)
+
+print "18. verify that locals() works"
+
+def f(x):
+ def g(y):
+ def h(z):
+ return y + z
+ w = x + y
+ y += 3
+ return locals()
+ return g
+
+d = f(2)(4)
+verify(d.has_key('h'))
+del d['h']
+verify(d == {'x': 2, 'y': 7, 'w': 6})