summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_syntax.py
blob: 6605e27d725bbc7b8341a499185a5bad24cd6b45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import re
import unittest

import test_support

class SyntaxTestCase(unittest.TestCase):

    def _check_error(self, code, errtext,
                     filename="<testcase>", mode="exec"):
        """Check that compiling code raises SyntaxError with errtext.

        errtest is a regular expression that must be present in the
        test of the exception raised.
        """
        try:
            compile(code, filename, mode)
        except SyntaxError, err:
            mo = re.search(errtext, str(err))
            if mo is None:
                self.fail("SyntaxError did not contain '%s'" % `errtext`)
        else:
            self.fail("compile() did not raise SyntaxError")

    def test_assign_call(self):
        self._check_error("f() = 1", "assign")

    def test_assign_del(self):
        self._check_error("del f()", "delete")

def test_main():
    test_support.run_unittest(SyntaxTestCase)

if __name__ == "__main__":
    test_main()