Change a variable type to avoid signed overflow; replace repeated '19999' constant...
[python.git] / Lib / test / test_global.py
blob22e4b254c2228de9f4a43e53a194cbddb403019c
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
6 import warnings
7 warnings.filterwarnings("error", module="<test string>")
9 class GlobalTests(unittest.TestCase):
11 def test1(self):
12 prog_text_1 = """\
13 def wrong1():
14 a = 1
15 b = 2
16 global a
17 global b
18 """
19 check_syntax_error(self, prog_text_1)
21 def test2(self):
22 prog_text_2 = """\
23 def wrong2():
24 print x
25 global x
26 """
27 check_syntax_error(self, prog_text_2)
29 def test3(self):
30 prog_text_3 = """\
31 def wrong3():
32 print x
33 x = 2
34 global x
35 """
36 check_syntax_error(self, prog_text_3)
38 def test4(self):
39 prog_text_4 = """\
40 global x
41 x = 2
42 """
43 # this should work
44 compile(prog_text_4, "<test string>", "exec")
47 def test_main():
48 run_unittest(GlobalTests)
50 if __name__ == "__main__":
51 test_main()