mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
[3.13] gh-121804: Always show error location for SyntaxError's in new repl (GH-121886) (#123148)
(cherry picked from commit 354d55eb1f
)
This commit is contained in:
parent
21399a0963
commit
c8f4069ab1
5 changed files with 29 additions and 7 deletions
|
@ -88,6 +88,20 @@ class TestSimpleInteract(unittest.TestCase):
|
|||
self.assertFalse(result)
|
||||
self.assertIn('SyntaxError', f.getvalue())
|
||||
|
||||
@force_not_colorized
|
||||
def test_runsource_show_syntax_error_location(self):
|
||||
console = InteractiveColoredConsole()
|
||||
source = "def f(x, x): ..."
|
||||
f = io.StringIO()
|
||||
with contextlib.redirect_stderr(f):
|
||||
result = console.runsource(source)
|
||||
self.assertFalse(result)
|
||||
r = """
|
||||
def f(x, x): ...
|
||||
^
|
||||
SyntaxError: duplicate argument 'x' in function definition"""
|
||||
self.assertIn(r, f.getvalue())
|
||||
|
||||
def test_runsource_shows_syntax_error_for_failed_compilation(self):
|
||||
console = InteractiveColoredConsole()
|
||||
source = "print('Hello, world!'"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue