[Python-checkins] r45897 - in python/trunk: Lib/test/test_syntax.py Misc/NEWS Parser/parsetok.c

martin.v.loewis python-checkins at python.org
Thu May 4 07:51:05 CEST 2006


Author: martin.v.loewis
Date: Thu May 4 07:51:03 2006
New Revision: 45897
Modified:
 python/trunk/Lib/test/test_syntax.py
 python/trunk/Misc/NEWS
 python/trunk/Parser/parsetok.c
Log:
Patch #1475845: Raise IndentationError for unexpected indent.
Modified: python/trunk/Lib/test/test_syntax.py
==============================================================================
--- python/trunk/Lib/test/test_syntax.py	(original)
+++ python/trunk/Lib/test/test_syntax.py	Thu May 4 07:51:03 2006
@@ -243,15 +243,18 @@
 class SyntaxTestCase(unittest.TestCase):
 
 def _check_error(self, code, errtext,
- filename="<testcase>", mode="exec"):
+ filename="<testcase>", mode="exec", subclass=None):
 """Check that compiling code raises SyntaxError with errtext.
 
 errtest is a regular expression that must be present in the
- test of the exception raised.
+ test of the exception raised. If subclass is specified it
+ is the expected subclass of SyntaxError (e.g. IndentationError).
 """
 try:
 compile(code, filename, mode)
 except SyntaxError, err:
+ if subclass and not isinstance(err, subclass):
+ self.fail("SyntaxError is not a %s" % subclass.__name__)
 mo = re.search(errtext, str(err))
 if mo is None:
 self.fail("SyntaxError did not contain '%r'" % (errtext,))
@@ -290,6 +293,19 @@
 :""")
 self._check_error(source, "nested scope")
 
+ def test_unexpected_indent(self):
+ self._check_error("foo()\n bar()\n", "unexpected indent",
+ subclass=IndentationError)
+
+ def test_no_indent(self):
+ self._check_error("if 1:\nfoo()", "expected an indented block",
+ subclass=IndentationError)
+
+ def test_bad_outdent(self):
+ self._check_error("if 1:\n foo()\n bar()",
+ "unindent does not match .* level",
+ subclass=IndentationError)
+
 def test_main():
 test_support.run_unittest(SyntaxTestCase)
 from test import test_syntax
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Thu May 4 07:51:03 2006
@@ -12,6 +12,8 @@
 Core and builtins
 -----------------
 
+- Patch #1475845: Raise IndentationError for unexpected indent.
+
 - Patch #1479181: split open() and file() from being aliases for each other.
 
 - Bug #1465834: 'bdist_wininst preinstall script support' was fixed
Modified: python/trunk/Parser/parsetok.c
==============================================================================
--- python/trunk/Parser/parsetok.c	(original)
+++ python/trunk/Parser/parsetok.c	Thu May 4 07:51:03 2006
@@ -194,8 +194,10 @@
 		if ((err_ret->error =
 		 PyParser_AddToken(ps, (int)type, str, tok->lineno, col_offset,
 				 &(err_ret->expected))) != E_OK) {
-			if (err_ret->error != E_DONE)
+			if (err_ret->error != E_DONE) {
 				PyObject_FREE(str);
+				err_ret->token = type;
+			}				
 			break;
 		}
 	}


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /