Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / lib / python2.4 / test / test_syntax.py
CommitLineData
920dae64
AT
1import re
2import unittest
3import warnings
4
5from test import test_support
6
7class SyntaxTestCase(unittest.TestCase):
8
9 def _check_error(self, code, errtext,
10 filename="<testcase>", mode="exec"):
11 """Check that compiling code raises SyntaxError with errtext.
12
13 errtest is a regular expression that must be present in the
14 test of the exception raised.
15 """
16 try:
17 compile(code, filename, mode)
18 except SyntaxError, err:
19 mo = re.search(errtext, str(err))
20 if mo is None:
21 self.fail("SyntaxError did not contain '%r'" % (errtext,))
22 else:
23 self.fail("compile() did not raise SyntaxError")
24
25 def test_assign_call(self):
26 self._check_error("f() = 1", "assign")
27
28 def test_assign_del(self):
29 self._check_error("del f()", "delete")
30
31 def test_global_err_then_warn(self):
32 # Bug tickler: The SyntaxError raised for one global statement
33 # shouldn't be clobbered by a SyntaxWarning issued for a later one.
34 source = re.sub('(?m)^ *:', '', """\
35 :def error(a):
36 : global a # SyntaxError
37 :def warning():
38 : b = 1
39 : global b # SyntaxWarning
40 :""")
41 warnings.filterwarnings(action='ignore', category=SyntaxWarning)
42 self._check_error(source, "global")
43 warnings.filters.pop(0)
44
45def test_main():
46 test_support.run_unittest(SyntaxTestCase)
47
48if __name__ == "__main__":
49 test_main()