summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_syntax.py
diff options
context:
space:
mode:
authorDong-hee Na <donghee.na@python.org>2023-01-30 23:33:54 (GMT)
committerGitHub <noreply@github.com>2023-01-30 23:33:54 (GMT)
commite867c1b753424d8d3f9c9ba0b431d007fd958c80 (patch)
tree9def8e6c605998963cb4483da7110cf490410bad /Lib/test/test_syntax.py
parent28db978d7f134edf6c86f21c42e15003511e7e9b (diff)
downloadcpython-e867c1b753424d8d3f9c9ba0b431d007fd958c80.zip
cpython-e867c1b753424d8d3f9c9ba0b431d007fd958c80.tar.gz
cpython-e867c1b753424d8d3f9c9ba0b431d007fd958c80.tar.bz2
gh-101400: Fix incorrect lineno in exception message on continue/break which are not in a loop (#101413)
Diffstat (limited to 'Lib/test/test_syntax.py')
-rw-r--r--Lib/test/test_syntax.py30
1 files changed, 17 insertions, 13 deletions
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index cb284195..f236535 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -1957,9 +1957,6 @@ class SyntaxTestCase(unittest.TestCase):
"""
self._check_error(source, "parameter and nonlocal", lineno=3)
- def test_break_outside_loop(self):
- self._check_error("break", "outside loop")
-
def test_yield_outside_function(self):
self._check_error("if 0: yield", "outside function")
self._check_error("if 0: yield\nelse: x=1", "outside function")
@@ -1988,20 +1985,27 @@ class SyntaxTestCase(unittest.TestCase):
"outside function")
def test_break_outside_loop(self):
- self._check_error("if 0: break", "outside loop")
- self._check_error("if 0: break\nelse: x=1", "outside loop")
- self._check_error("if 1: pass\nelse: break", "outside loop")
- self._check_error("class C:\n if 0: break", "outside loop")
+ msg = "outside loop"
+ self._check_error("break", msg, lineno=1)
+ self._check_error("if 0: break", msg, lineno=1)
+ self._check_error("if 0: break\nelse: x=1", msg, lineno=1)
+ self._check_error("if 1: pass\nelse: break", msg, lineno=2)
+ self._check_error("class C:\n if 0: break", msg, lineno=2)
self._check_error("class C:\n if 1: pass\n else: break",
- "outside loop")
+ msg, lineno=3)
+ self._check_error("with object() as obj:\n break",
+ msg, lineno=2)
def test_continue_outside_loop(self):
- self._check_error("if 0: continue", "not properly in loop")
- self._check_error("if 0: continue\nelse: x=1", "not properly in loop")
- self._check_error("if 1: pass\nelse: continue", "not properly in loop")
- self._check_error("class C:\n if 0: continue", "not properly in loop")
+ msg = "not properly in loop"
+ self._check_error("if 0: continue", msg, lineno=1)
+ self._check_error("if 0: continue\nelse: x=1", msg, lineno=1)
+ self._check_error("if 1: pass\nelse: continue", msg, lineno=2)
+ self._check_error("class C:\n if 0: continue", msg, lineno=2)
self._check_error("class C:\n if 1: pass\n else: continue",
- "not properly in loop")
+ msg, lineno=3)
+ self._check_error("with object() as obj:\n continue",
+ msg, lineno=2)
def test_unexpected_indent(self):
self._check_error("foo()\n bar()\n", "unexpected indent",