[Python-checkins] python/dist/src/Lib/test test_scope.py,1.14.2.2,1.14.2.3

jhylton@sourceforge.net jhylton@sourceforge.net
Sat, 20 Apr 2002 11:21:05 -0700


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

Modified Files:
      Tag: release21-maint
	test_scope.py 
Log Message:
Backport fixes for two nested scopes bugs.

frameobject.c: make sure free and cell vars make it into locals, which
    makes eval work.

bltinmodule.c & ceval.c: make sure a code object with free variables
    that is passed to exec or eval raises an exception.

Also duplicate the current trunk test suite in the 2.1 branch, except
for certain necessary changes: different warnings raised by 2.1, need
for __future__.



Index: test_scope.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_scope.py,v
retrieving revision 1.14.2.2
retrieving revision 1.14.2.3
diff -C2 -d -r1.14.2.2 -r1.14.2.3
*** test_scope.py	23 May 2001 13:26:29 -0000	1.14.2.2
--- test_scope.py	20 Apr 2002 18:21:03 -0000	1.14.2.3
***************
*** 1,5 ****
  from __future__ import nested_scopes
  
! from test.test_support import verify, TestFailed, check_syntax
  
  print "1. simple nesting"
--- 1,9 ----
  from __future__ import nested_scopes
  
! from test_support import verify, TestFailed, check_syntax
! 
! import warnings
! warnings.filterwarnings("ignore", r"(import \*|local name|unqualified)",
!                         SyntaxWarning, "<string>")
  
  print "1. simple nesting"
***************
*** 180,184 ****
  print "11. unoptimized namespaces"
  
! check_syntax("""from __future__ import nested_scopes
  def unoptimized_clash1(strip):
      def f(s):
--- 184,189 ----
  print "11. unoptimized namespaces"
  
! check_syntax("""\
! from __future__ import nested_scopes
  def unoptimized_clash1(strip):
      def f(s):
***************
*** 188,192 ****
  """)
  
! check_syntax("""from __future__ import nested_scopes
  def unoptimized_clash2():
      from string import *
--- 193,198 ----
  """)
  
! check_syntax("""\
! from __future__ import nested_scopes
  def unoptimized_clash2():
      from string import *
***************
*** 196,200 ****
  """)
  
! check_syntax("""from __future__ import nested_scopes
  def unoptimized_clash2():
      from string import *
--- 202,207 ----
  """)
  
! check_syntax("""\
! from __future__ import nested_scopes
  def unoptimized_clash2():
      from string import *
***************
*** 206,210 ****
  
  # XXX could allow this for exec with const argument, but what's the point
! check_syntax("""from __future__ import nested_scopes
  def error(y):
      exec "a = 1"
--- 213,218 ----
  
  # XXX could allow this for exec with const argument, but what's the point
! check_syntax("""\
! from __future__ import nested_scopes
  def error(y):
      exec "a = 1"
***************
*** 214,218 ****
  """)
  
! check_syntax("""from __future__ import nested_scopes
  def f(x):
      def g():
--- 222,227 ----
  """)
  
! check_syntax("""\
! from __future__ import nested_scopes
  def f(x):
      def g():
***************
*** 221,225 ****
  """)
  
! check_syntax("""from __future__ import nested_scopes
  def f():
      def g():
--- 230,235 ----
  """)
  
! check_syntax("""\
! from __future__ import nested_scopes
  def f():
      def g():
***************
*** 230,233 ****
--- 240,244 ----
  # and verify a few cases that should work
  
+ exec """
  def noproblem1():
      from string import *
***************
*** 244,247 ****
--- 255,259 ----
          global y
          y = x
+ """
  
  print "12. lambdas"
***************
*** 468,469 ****
--- 480,533 ----
  adaptgetter("foo", TestClass, (1, ""))
  sys.settrace(None)
+ 
+ ##try: sys.settrace()
+ ##except TypeError: pass
+ ##else: raise TestFailed, 'sys.settrace() did not raise TypeError'
+ 
+ print "20. eval and exec with free variables"
+ 
+ def f(x):
+     return lambda: x + 1
+ 
+ g = f(3)
+ try:
+     eval(g.func_code)
+ except TypeError:
+     pass
+ else:
+     print "eval() should have failed, because code contained free vars"
+ 
+ try:
+     exec g.func_code
+ except TypeError:
+     pass
+ else:
+     print "exec should have failed, because code contained free vars"
+ 
+ print "21. list comprehension with local variables"
+ 
+ try:
+     print bad
+ except NameError:
+     pass
+ else:
+     print "bad should not be defined"
+ 
+ def x():
+     [bad for s in 'a b' for bad in s.split()]
+ 
+ x()
+ try:
+     print bad
+ except NameError:
+     pass
+ 
+ print "22. eval with free variables"
+ 
+ def f(free):
+     def g():
+         free
+         eval("free + 1")
+     return g
+ 
+ f(4)()