]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add tests for recent changes:
authorJeremy Hylton <jeremy@alum.mit.edu>
Wed, 21 Mar 2001 16:44:39 +0000 (16:44 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Wed, 21 Mar 2001 16:44:39 +0000 (16:44 +0000)
- global stmt in class does not affect free vars in methods
- locals() works with free and cell vars

Lib/test/output/test_scope
Lib/test/test_scope.py

index b00f9f51677341df3fa55014161ca6662867ec6a..af7fe31e2b9c209eaa396929b1d3283233f73655 100644 (file)
@@ -15,3 +15,5 @@ test_scope
 14. complex definitions
 15. scope of global statements
 16. check leaks
+17. class and global
+18. verify that locals() works
index 5df0328d6d73f4049f34590da58e4c67b7db3c7d..d6367b24fb9d4ae53e36aa3fe15b0ccafc92d00a 100644 (file)
@@ -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})