~ubuntu-branches/ubuntu/trusty/python3.4/trusty-proposed

« back to all changes in this revision

Viewing changes to Lib/test/test_global.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-11-25 09:44:27 UTC
  • Revision ID: package-import@ubuntu.com-20131125094427-lzxj8ap5w01lmo7f
Tags: upstream-3.4~b1
ImportĀ upstreamĀ versionĀ 3.4~b1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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)
 
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)
 
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)
 
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()