blob: 7670ad1dedfb841d6d523330c2b802e0ef2d8e35 [file] [log] [blame]
Jeremy Hylton8e43cd72001-02-28 01:51:01 +00001"""Verify that warnings are issued for global statements following use"""
2
3from test_support import check_syntax
4
5import warnings
6
7warnings.filterwarnings("error", category=SyntaxWarning, module=__name__)
8
9def compile_and_catch_warning(text):
10 try:
11 compile(text, "<test code>", "exec")
12 except SyntaxWarning, msg:
13 print "got SyntaxWarning as expected"
14 else:
15 print "expected SyntaxWarning"
16
17prog_text_1 = """
18def wrong1():
19 a = 1
20 b = 2
21 global a
22 global b
23"""
24compile_and_catch_warning(prog_text_1)
25
26prog_text_2 = """
27def wrong2():
28 print x
29 global x
30"""
31compile_and_catch_warning(prog_text_2)
32
33prog_text_3 = """
34def wrong3():
35 print x
36 x = 2
37 global x
38"""
39compile_and_catch_warning(prog_text_3)
40