move sections
[python/dscho.git] / Lib / test / test_global.py
blobabcb193e5eef8ef0c44e9ea1b80cb33603a68eb9
1 """Verify that warnings are issued for global statements following use."""
3 from test.test_support import run_unittest, check_syntax_error
4 import unittest
5 import warnings
8 class GlobalTests(unittest.TestCase):
10 def test1(self):
11 prog_text_1 = """\
12 def wrong1():
13 a = 1
14 b = 2
15 global a
16 global b
17 """
18 check_syntax_error(self, prog_text_1)
20 def test2(self):
21 prog_text_2 = """\
22 def wrong2():
23 print x
24 global x
25 """
26 check_syntax_error(self, prog_text_2)
28 def test3(self):
29 prog_text_3 = """\
30 def wrong3():
31 print x
32 x = 2
33 global x
34 """
35 check_syntax_error(self, prog_text_3)
37 def test4(self):
38 prog_text_4 = """\
39 global x
40 x = 2
41 """
42 # this should work
43 compile(prog_text_4, "<test string>", "exec")
46 def test_main():
47 with warnings.catch_warnings():
48 warnings.filterwarnings("error", module="<test string>")
49 run_unittest(GlobalTests)
51 if __name__ == "__main__":
52 test_main()