Apparently the code to forestall Tk eating events was too aggressive (Tk user input...
[python/dscho.git] / Lib / test / test_global.py
blobfb10533ae46b50bbcbe40505593c3edfcd4bb099
1 """Verify that warnings are issued for global statements following use."""
3 from test_support import check_syntax
5 import warnings
7 warnings.filterwarnings("error", module="<test code>")
9 def compile_and_check(text, should_fail=1):
10 try:
11 compile(text, "<test code>", "exec")
12 except SyntaxError, msg:
13 if should_fail:
14 print "got SyntaxError as expected"
15 else:
16 print "raised unexpected SyntaxError:", text
17 else:
18 if should_fail:
19 print "should have raised SyntaxError:", text
20 else:
21 print "as expected, no SyntaxError"
23 prog_text_1 = """
24 def wrong1():
25 a = 1
26 b = 2
27 global a
28 global b
29 """
30 compile_and_check(prog_text_1)
32 prog_text_2 = """
33 def wrong2():
34 print x
35 global x
36 """
37 compile_and_check(prog_text_2)
39 prog_text_3 = """
40 def wrong3():
41 print x
42 x = 2
43 global x
44 """
45 compile_and_check(prog_text_3)
47 prog_text_4 = """
48 global x
49 x = 2
50 """
51 compile_and_check(prog_text_4, 0)