Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 26d64ae

Browse files
committed
rewrite nocaret test to not rely on a specific SyntaxError
1 parent b0b384b commit 26d64ae

2 files changed

Lines changed: 4 additions & 13 deletions

File tree

Lib/test/badsyntax_nocaret.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

Lib/test/test_traceback.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66
import unittest
77
import re
8-
from test.support import run_unittest, is_jython, Error, captured_output
8+
from test.support import run_unittest, Error, captured_output
99
from test.support import TESTFN, unlink
1010

1111
import traceback
@@ -29,10 +29,6 @@ def syntax_error_with_caret(self):
2929
def syntax_error_with_caret_2(self):
3030
compile("1 +\n", "?", "exec")
3131

32-
def syntax_error_without_caret(self):
33-
# XXX why doesn't compile raise the same traceback?
34-
import test.badsyntax_nocaret
35-
3632
def syntax_error_bad_indentation(self):
3733
compile("def spam():\n print(1)\n print(2)", "?", "exec")
3834

@@ -51,13 +47,10 @@ def test_caret(self):
5147
self.assertTrue(err[1].find("+") == err[2].find("^")) # in the right place
5248

5349
def test_nocaret(self):
54-
if is_jython:
55-
# jython adds a caret in this case (why shouldn't it?)
56-
return
57-
err = self.get_exception_format(self.syntax_error_without_caret,
58-
SyntaxError)
50+
exc = SyntaxError("error", ("x.py", 23, None, "bad syntax"))
51+
err = traceback.format_exception_only(SyntaxError, exc)
5952
self.assertEqual(len(err), 3)
60-
self.assertTrue(err[1].strip() == "[x for x in x] = x")
53+
self.assertEqual(err[1].strip(), "bad syntax")
6154

6255
def test_bad_indentation(self):
6356
err = self.get_exception_format(self.syntax_error_bad_indentation,

0 commit comments

Comments
 (0)