[Python-checkins] CVS: python/dist/src/Lib/test test_scope.py,1.9,1.10

Guido van Rossum gvanrossum@users.sourceforge.net
Thu, 01 Mar 2001 12:35:47 -0800


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv12954

Modified Files:
	test_scope.py 
Log Message:
Test interaction of global and nested scopes -- thanks to Samuele Pedroni.

Index: test_scope.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_scope.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** test_scope.py	2001/02/27 20:23:58	1.9
--- test_scope.py	2001/03/01 20:35:45	1.10
***************
*** 319,320 ****
--- 319,385 ----
  
  verify(makeAddPair((1, 2))((100, 200)) == (101,202))
+ 
+ print "15. scope of global statements"
+ # Examples posted by Samuele Pedroni to python-dev on 3/1/2001
+ 
+ # I
+ x = 7
+ def f():
+     x = 1
+     def g():
+         global x
+         def i():
+             def h():
+                 return x
+             return h()
+         return i()
+     return g()
+ verify(f() == 7)
+ verify(x == 7)
+ 
+ # II
+ x = 7
+ def f():
+     x = 1
+     def g():
+         x = 2
+         def i():
+             def h():
+                 return x
+             return h()
+         return i()
+     return g()
+ verify(f() == 2)
+ verify(x == 7)
+ 
+ # III
+ x = 7
+ def f():
+     x = 1
+     def g():
+         global x
+         x = 2
+         def i():
+             def h():
+                 return x
+             return h()
+         return i()
+     return g()
+ verify(f() == 2)
+ verify(x == 2)
+ 
+ # IV
+ x = 7
+ def f():
+     x = 3
+     def g():
+         global x
+         x = 2
+         def i():
+             def h():
+                 return x
+             return h()
+         return i()
+     return g()
+ verify(f() == 2)
+ verify(x == 2)