Add test case for global stmt at module level.

Fix test_grammar so that it ignores warning about global stmt at
module level in exec.
This commit is contained in:
Jeremy Hylton 2001-02-28 23:49:19 +00:00
parent 3dd5ad3b4f
commit 2922ea8235
3 changed files with 10 additions and 0 deletions

View File

@ -2,3 +2,4 @@ test_global
got SyntaxError as expected got SyntaxError as expected
got SyntaxError as expected got SyntaxError as expected
got SyntaxError as expected got SyntaxError as expected
got SyntaxError as expected

View File

@ -37,3 +37,9 @@ def wrong3():
global x global x
""" """
compile_and_catch_warning(prog_text_3) compile_and_catch_warning(prog_text_3)
prog_text_4 = """
global x
x = 2
"""
compile_and_catch_warning(prog_text_4)

View File

@ -411,6 +411,9 @@ if g.has_key('__builtins__'): del g['__builtins__']
if g != {'z': 1}: raise TestFailed, 'exec \'z = 1\' in g' if g != {'z': 1}: raise TestFailed, 'exec \'z = 1\' in g'
g = {} g = {}
l = {} l = {}
import warnings
warnings.filterwarnings("ignore", "global statement", module="<string>")
exec 'global a; a = 1; b = 2' in g, l exec 'global a; a = 1; b = 2' in g, l
if g.has_key('__builtins__'): del g['__builtins__'] if g.has_key('__builtins__'): del g['__builtins__']
if l.has_key('__builtins__'): del l['__builtins__'] if l.has_key('__builtins__'): del l['__builtins__']