File tree 1 file changed +61
-0
lines changed 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change
1
+ """Verify that warnings are issued for global statements following use."""
2
+
3
+ from test .support import run_unittest , check_syntax_error , check_warnings
4
+ import unittest
5
+ import warnings
6
+
7
+
8
+ class GlobalTests (unittest .TestCase ):
9
+
10
+ def setUp (self ):
11
+ self ._warnings_manager = check_warnings ()
12
+ self ._warnings_manager .__enter__ ()
13
+ warnings .filterwarnings ("error" , module = "<test string>" )
14
+
15
+ def tearDown (self ):
16
+ self ._warnings_manager .__exit__ (None , None , None )
17
+
18
+
19
+ def test1 (self ):
20
+ prog_text_1 = """\
21
+ def wrong1():
22
+ a = 1
23
+ b = 2
24
+ global a
25
+ global b
26
+ """
27
+ check_syntax_error (self , prog_text_1 , lineno = 4 , offset = 5 )
28
+
29
+ def test2 (self ):
30
+ prog_text_2 = """\
31
+ def wrong2():
32
+ print(x)
33
+ global x
34
+ """
35
+ check_syntax_error (self , prog_text_2 , lineno = 3 , offset = 5 )
36
+
37
+ def test3 (self ):
38
+ prog_text_3 = """\
39
+ def wrong3():
40
+ print(x)
41
+ x = 2
42
+ global x
43
+ """
44
+ check_syntax_error (self , prog_text_3 , lineno = 4 , offset = 5 )
45
+
46
+ def test4 (self ):
47
+ prog_text_4 = """\
48
+ global x
49
+ x = 2
50
+ """
51
+ # this should work
52
+ compile (prog_text_4 , "<test string>" , "exec" )
53
+
54
+
55
+ def test_main ():
56
+ with warnings .catch_warnings ():
57
+ warnings .filterwarnings ("error" , module = "<test string>" )
58
+ run_unittest (GlobalTests )
59
+
60
+ if __name__ == "__main__" :
61
+ test_main ()
You can’t perform that action at this time.
0 commit comments