mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
test_global was broken by some recent checkin. Repairing.
This commit is contained in:
parent
7a25765f48
commit
fc35de409b
2 changed files with 15 additions and 9 deletions
|
@ -2,4 +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
|
as expected, no SyntaxError
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
"""Verify that warnings are issued for global statements following use"""
|
"""Verify that warnings are issued for global statements following use."""
|
||||||
|
|
||||||
from test_support import check_syntax
|
from test_support import check_syntax
|
||||||
|
|
||||||
|
@ -6,13 +6,19 @@ import warnings
|
||||||
|
|
||||||
warnings.filterwarnings("error", module="<test code>")
|
warnings.filterwarnings("error", module="<test code>")
|
||||||
|
|
||||||
def compile_and_catch_warning(text):
|
def compile_and_check(text, should_fail=1):
|
||||||
try:
|
try:
|
||||||
compile(text, "<test code>", "exec")
|
compile(text, "<test code>", "exec")
|
||||||
except SyntaxError, msg:
|
except SyntaxError, msg:
|
||||||
print "got SyntaxError as expected"
|
if should_fail:
|
||||||
|
print "got SyntaxError as expected"
|
||||||
|
else:
|
||||||
|
print "raised unexpected SyntaxError:", text
|
||||||
else:
|
else:
|
||||||
print "expected SyntaxError"
|
if should_fail:
|
||||||
|
print "should have raised SyntaxError:", text
|
||||||
|
else:
|
||||||
|
print "as expected, no SyntaxError"
|
||||||
|
|
||||||
prog_text_1 = """
|
prog_text_1 = """
|
||||||
def wrong1():
|
def wrong1():
|
||||||
|
@ -21,14 +27,14 @@ def wrong1():
|
||||||
global a
|
global a
|
||||||
global b
|
global b
|
||||||
"""
|
"""
|
||||||
compile_and_catch_warning(prog_text_1)
|
compile_and_check(prog_text_1)
|
||||||
|
|
||||||
prog_text_2 = """
|
prog_text_2 = """
|
||||||
def wrong2():
|
def wrong2():
|
||||||
print x
|
print x
|
||||||
global x
|
global x
|
||||||
"""
|
"""
|
||||||
compile_and_catch_warning(prog_text_2)
|
compile_and_check(prog_text_2)
|
||||||
|
|
||||||
prog_text_3 = """
|
prog_text_3 = """
|
||||||
def wrong3():
|
def wrong3():
|
||||||
|
@ -36,10 +42,10 @@ def wrong3():
|
||||||
x = 2
|
x = 2
|
||||||
global x
|
global x
|
||||||
"""
|
"""
|
||||||
compile_and_catch_warning(prog_text_3)
|
compile_and_check(prog_text_3)
|
||||||
|
|
||||||
prog_text_4 = """
|
prog_text_4 = """
|
||||||
global x
|
global x
|
||||||
x = 2
|
x = 2
|
||||||
"""
|
"""
|
||||||
compile_and_catch_warning(prog_text_4)
|
compile_and_check(prog_text_4, 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue