[Python-checkins] CVS: python/dist/src/Lib/test test_scope.py,1.12,1.13
Jeremy Hylton
jhylton@users.sourceforge.net
Wed, 21 Mar 2001 08:44:41 -0800
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv32524
Modified Files:
test_scope.py
Log Message:
Add tests for recent changes:
- global stmt in class does not affect free vars in methods
- locals() works with free and cell vars
Index: test_scope.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_scope.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** test_scope.py 2001/03/16 08:29:48 1.12
--- test_scope.py 2001/03/21 16:44:39 1.13
***************
*** 406,407 ****
--- 406,437 ----
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})