symbian-qemu-0.9.1-12/python-2.6.1/Lib/test/test_global.py
changeset 1 2fb8b9db1c86
equal deleted inserted replaced
0:ffa851df0825 1:2fb8b9db1c86
       
     1 """Verify that warnings are issued for global statements following use."""
       
     2 
       
     3 from test.test_support import run_unittest, check_syntax_error
       
     4 import unittest
       
     5 
       
     6 import warnings
       
     7 warnings.filterwarnings("error", module="<test string>")
       
     8 
       
     9 class GlobalTests(unittest.TestCase):
       
    10 
       
    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)
       
    20 
       
    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)
       
    28 
       
    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)
       
    37 
       
    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")
       
    45 
       
    46 
       
    47 def test_main():
       
    48     run_unittest(GlobalTests)
       
    49 
       
    50 if __name__ == "__main__":
       
    51     test_main()