diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2002-05-31 14:08:29 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2002-05-31 14:08:29 (GMT) |
commit | 05ab2e693cf5bed23e14058cf9eb458441769122 (patch) | |
tree | ee0a3897beb1147586237572e01d073b24ea8924 /Lib/test/test_syntax.py | |
parent | 5352d8c0c6ae6cce7af2fef7a3fb9ee26c6aad9b (diff) | |
download | cpython-05ab2e693cf5bed23e14058cf9eb458441769122.zip cpython-05ab2e693cf5bed23e14058cf9eb458441769122.tar.gz cpython-05ab2e693cf5bed23e14058cf9eb458441769122.tar.bz2 |
Fix SF bug [ 561825 ] Confusing error for "del f()"
In the error message, say del for del and assign for everything else.
Diffstat (limited to 'Lib/test/test_syntax.py')
-rw-r--r-- | Lib/test/test_syntax.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py new file mode 100644 index 0000000..6605e27 --- /dev/null +++ b/Lib/test/test_syntax.py @@ -0,0 +1,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() |