Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_global.py @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | 13b8ad679def |
| children | 3748bca4d869 55d8c35322a7 |
| rev | line source |
|---|---|
|
16925
faa7aaeb0210
test_global was broken by some recent checkin. Repairing.
Tim Peters <tim.peters@gmail.com>
parents:
16874
diff
changeset
|
1 """Verify that warnings are issued for global statements following use.""" |
|
16822
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
2 |
|
40217
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
3 from test.test_support import run_unittest, check_syntax_error |
|
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
4 import unittest |
|
16822
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
5 |
|
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
6 import warnings |
|
40217
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
7 warnings.filterwarnings("error", module="<test string>") |
|
16822
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
8 |
|
40217
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
9 class GlobalTests(unittest.TestCase): |
|
16822
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
10 |
|
40217
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
11 def test1(self): |
|
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
12 prog_text_1 = """\ |
|
16822
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
13 def wrong1(): |
|
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
14 a = 1 |
|
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
15 b = 2 |
|
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
16 global a |
|
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
17 global b |
|
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
18 """ |
|
40217
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
19 check_syntax_error(self, prog_text_1) |
|
16822
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
20 |
|
40217
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
21 def test2(self): |
|
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
22 prog_text_2 = """\ |
|
16822
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
23 def wrong2(): |
|
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
24 print x |
|
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
25 global x |
|
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
26 """ |
|
40217
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
27 check_syntax_error(self, prog_text_2) |
|
16822
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
28 |
|
40217
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
29 def test3(self): |
|
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
30 prog_text_3 = """\ |
|
16822
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
31 def wrong3(): |
|
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
32 print x |
|
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
33 x = 2 |
|
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
34 global x |
|
0f0efc2d12f1
verify that warnings are issued for bogus uses of global
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
35 """ |
|
40217
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
36 check_syntax_error(self, prog_text_3) |
|
16874
79bbf7ad0fc1
Add test case for global stmt at module level.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16861
diff
changeset
|
37 |
|
40217
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
38 def test4(self): |
|
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
39 prog_text_4 = """\ |
|
16874
79bbf7ad0fc1
Add test case for global stmt at module level.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16861
diff
changeset
|
40 global x |
|
79bbf7ad0fc1
Add test case for global stmt at module level.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16861
diff
changeset
|
41 x = 2 |
|
79bbf7ad0fc1
Add test case for global stmt at module level.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16861
diff
changeset
|
42 """ |
|
40217
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
43 # this should work |
|
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
44 compile(prog_text_4, "<test string>", "exec") |
|
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
45 |
|
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
46 |
|
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
47 def test_main(): |
|
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
48 run_unittest(GlobalTests) |
|
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
49 |
|
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
50 if __name__ == "__main__": |
|
13b8ad679def
Convert test_global, test_scope and test_grammar to unittest.
Georg Brandl <georg@python.org>
parents:
24442
diff
changeset
|
51 test_main() |
