4 from test
import test_support
6 class SyntaxTestCase(unittest
.TestCase
):
8 def _check_error(self
, code
, errtext
,
9 filename
="<testcase>", mode
="exec"):
10 """Check that compiling code raises SyntaxError with errtext.
12 errtest is a regular expression that must be present in the
13 test of the exception raised.
16 compile(code
, filename
, mode
)
17 except SyntaxError, err
:
18 mo
= re
.search(errtext
, str(err
))
20 self
.fail("SyntaxError did not contain '%s'" % `errtext`
)
22 self
.fail("compile() did not raise SyntaxError")
24 def test_assign_call(self
):
25 self
._check
_error
("f() = 1", "assign")
27 def test_assign_del(self
):
28 self
._check
_error
("del f()", "delete")
31 test_support
.run_unittest(SyntaxTestCase
)
33 if __name__
== "__main__":