Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / lib / python2.4 / test / test_global.py
CommitLineData
86530b38
AT
1"""Verify that warnings are issued for global statements following use."""
2
3from test.test_support import check_syntax
4
5import warnings
6
7warnings.filterwarnings("error", module="<test code>")
8
9def 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"
22
23prog_text_1 = """
24def wrong1():
25 a = 1
26 b = 2
27 global a
28 global b
29"""
30compile_and_check(prog_text_1)
31
32prog_text_2 = """
33def wrong2():
34 print x
35 global x
36"""
37compile_and_check(prog_text_2)
38
39prog_text_3 = """
40def wrong3():
41 print x
42 x = 2
43 global x
44"""
45compile_and_check(prog_text_3)
46
47prog_text_4 = """
48global x
49x = 2
50"""
51compile_and_check(prog_text_4, 0)