from test
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.
compile(code
, filename
, mode
)
mo
= re
.search(errtext
, str(err
))
self
.fail("SyntaxError did not contain '%r'" % (errtext
,))
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_global_err_then_warn(self
):
# Bug tickler: The SyntaxError raised for one global statement
# shouldn't be clobbered by a SyntaxWarning issued for a later one.
source
= re
.sub('(?m)^ *:', '', """\
: global b # SyntaxWarning
warnings
.filterwarnings(action
='ignore', category
=SyntaxWarning)
self
._check
_error
(source
, "global")
test_support
.run_unittest(SyntaxTestCase
)
if __name__
== "__main__":