summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2021-04-21 14:28:21 (GMT)
committerGitHub <noreply@github.com>2021-04-21 14:28:21 (GMT)
commit56c95dfe271b1242bdc8163d4677e311552c00cb (patch)
tree05ece745311032fba0f63e2cbd9a69c54b7e3ada /Lib/test
parentb0544ba77cf86074fb1adde00558c67ca75eeea1 (diff)
downloadcpython-56c95dfe271b1242bdc8163d4677e311552c00cb.zip
cpython-56c95dfe271b1242bdc8163d4677e311552c00cb.tar.gz
cpython-56c95dfe271b1242bdc8163d4677e311552c00cb.tar.bz2
bpo-43859: Improve the error message for IndentationError exceptions (GH-25431)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_exceptions.py2
-rw-r--r--Lib/test/test_syntax.py132
2 files changed, 133 insertions, 1 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index d93b0f16..e0e8191 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -179,7 +179,7 @@ class ExceptionTests(unittest.TestCase):
# should not apply to subclasses, see issue #31161
s = '''if True:\nprint "No indent"'''
- ckmsg(s, "expected an indented block", IndentationError)
+ ckmsg(s, "expected an indented block after 'if' statement on line 1", IndentationError)
s = '''if True:\n print()\n\texec "mixed tabs and spaces"'''
ckmsg(s, "inconsistent use of tabs and spaces in indentation", TabError)
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index 5f622b0..dc81964 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -926,6 +926,138 @@ Incomplete dictionary literals
Traceback (most recent call last):
SyntaxError: invalid syntax
+Specialized indentation errors:
+
+ >>> while condition:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'while' statement on line 1
+
+ >>> for x in range(10):
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'for' statement on line 1
+
+ >>> for x in range(10):
+ ... pass
+ ... else:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'else' statement on line 3
+
+ >>> async for x in range(10):
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'for' statement on line 1
+
+ >>> async for x in range(10):
+ ... pass
+ ... else:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'else' statement on line 3
+
+ >>> if something:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'if' statement on line 1
+
+ >>> if something:
+ ... pass
+ ... elif something_else:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'elif' statement on line 3
+
+ >>> if something:
+ ... pass
+ ... elif something_else:
+ ... pass
+ ... else:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'else' statement on line 5
+
+ >>> try:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'try' statement on line 1
+
+ >>> try:
+ ... something()
+ ... except A:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'except' statement on line 3
+
+ >>> try:
+ ... something()
+ ... except A:
+ ... pass
+ ... finally:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'finally' statement on line 5
+
+ >>> with A:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'with' statement on line 1
+
+ >>> with A as a, B as b:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'with' statement on line 1
+
+ >>> with (A as a, B as b):
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'with' statement on line 1
+
+ >>> async with A:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'with' statement on line 1
+
+ >>> async with A as a, B as b:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'with' statement on line 1
+
+ >>> async with (A as a, B as b):
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'with' statement on line 1
+
+ >>> def foo(x, /, y, *, z=2):
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after function definition on line 1
+
+ >>> class Blech(A):
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after class definition on line 1
+
+ >>> match something:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'match' statement on line 1
+
+ >>> match something:
+ ... case []:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'case' statement on line 2
+
+ >>> match something:
+ ... case []:
+ ... ...
+ ... case {}:
+ ... pass
+ Traceback (most recent call last):
+ IndentationError: expected an indented block after 'case' statement on line 4
+
Make sure that the old "raise X, Y[, Z]" form is gone:
>>> raise X, Y
Traceback (most recent call last):