mirror of
https://github.com/python/cpython.git
synced 2024-12-14 04:17:19 +08:00
04f357cffe
imports e.g. test_support must do so using an absolute package name such as "import test.test_support" or "from test import test_support". This also updates the README in Lib/test, and gets rid of the duplicate data dirctory in Lib/test/data (replaced by Lib/email/test/data). Now Tim and Jack can have at it. :)
35 lines
966 B
Python
35 lines
966 B
Python
import re
|
|
import unittest
|
|
|
|
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.
|
|
"""
|
|
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()
|