[Python-checkins] python/dist/src/Lib/test test_syntax.py,NONE,1.1
jhylton@users.sourceforge.net
jhylton@users.sourceforge.net
Fri, 31 May 2002 07:08:31 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv3390/Lib/test
Added Files:
test_syntax.py
Log Message:
Fix SF bug [ 561825 ] Confusing error for "del f()"
In the error message, say del for del and assign for everything else.
--- NEW FILE: test_syntax.py ---
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()