diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2006-05-04 05:51:03 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2006-05-04 05:51:03 (GMT) |
commit | 777367103c9ab487fb74ce3f3ac8ea2701de328e (patch) | |
tree | 4cdca2cd62358317f4b7b83e8a8416f2949df0b4 /Lib/test/test_syntax.py | |
parent | 61d168a55ed08de951c69213a47896f637306908 (diff) | |
download | cpython-777367103c9ab487fb74ce3f3ac8ea2701de328e.zip cpython-777367103c9ab487fb74ce3f3ac8ea2701de328e.tar.gz cpython-777367103c9ab487fb74ce3f3ac8ea2701de328e.tar.bz2 |
Patch #1475845: Raise IndentationError for unexpected indent.
Diffstat (limited to 'Lib/test/test_syntax.py')
-rw-r--r-- | Lib/test/test_syntax.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index b61debf..ce2e327 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -243,15 +243,18 @@ from test import test_support 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 @@ class SyntaxTestCase(unittest.TestCase): :""") 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 |