diff Lib/test/test_scope.py @ 17105:8ff24abeb388 legacy-trunk

Add tests for recent changes: - global stmt in class does not affect free vars in methods - locals() works with free and cell vars
author Jeremy Hylton <jeremy@alum.mit.edu>
date Wed, 21 Mar 2001 16:44:39 +0000
parents 743296ce052b
children a34293ced63b
line wrap: on
line diff
--- a/Lib/test/test_scope.py	Wed Mar 21 16:43:47 2001 +0000
+++ b/Lib/test/test_scope.py	Wed Mar 21 16:44:39 2001 +0000
@@ -405,3 +405,33 @@
     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})