mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-07 13:24:39 +08:00
Conditionally include failing examples rather than handle them in the testing code
This commit is contained in:
@@ -29,7 +29,6 @@ FAILING_EXAMPLES = [
|
|||||||
'from foo import a,',
|
'from foo import a,',
|
||||||
'from __future__ import whatever',
|
'from __future__ import whatever',
|
||||||
'from __future__ import braces',
|
'from __future__ import braces',
|
||||||
'from .__future__ import whatever',
|
|
||||||
'def f(x=3, y): pass',
|
'def f(x=3, y): pass',
|
||||||
'lambda x=3, y: x',
|
'lambda x=3, y: x',
|
||||||
'__debug__ = 1',
|
'__debug__ = 1',
|
||||||
@@ -216,7 +215,6 @@ FAILING_EXAMPLES = [
|
|||||||
'f"{\'\\\'}"',
|
'f"{\'\\\'}"',
|
||||||
'f"{#}"',
|
'f"{#}"',
|
||||||
"f'{1!b}'",
|
"f'{1!b}'",
|
||||||
"f'{1:{5:{3}}}'",
|
|
||||||
"f'{'",
|
"f'{'",
|
||||||
"f'{'",
|
"f'{'",
|
||||||
"f'}'",
|
"f'}'",
|
||||||
@@ -411,3 +409,17 @@ if sys.version_info[:2] >= (3, 8):
|
|||||||
FAILING_EXAMPLES += [
|
FAILING_EXAMPLES += [
|
||||||
"f'{1=!b}'",
|
"f'{1=!b}'",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if sys.version_info[:2] < (3, 12):
|
||||||
|
FAILING_EXAMPLES += [
|
||||||
|
# f-string expression part cannot include a backslash before 3.12
|
||||||
|
r'''f"{'\n'}"''',
|
||||||
|
# this compiles successfully but fails when evaluated in 3.12
|
||||||
|
"f'{1:{5:{3}}}'",
|
||||||
|
]
|
||||||
|
|
||||||
|
if sys.version_info[:2] < (3, 13):
|
||||||
|
# this compiles successfully but fails when evaluated in 3.13
|
||||||
|
FAILING_EXAMPLES += [
|
||||||
|
'from .__future__ import whatever',
|
||||||
|
]
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ def _get_actual_exception(code):
|
|||||||
# It's as simple as either an error or not.
|
# It's as simple as either an error or not.
|
||||||
warnings.filterwarnings('ignore', category=SyntaxWarning)
|
warnings.filterwarnings('ignore', category=SyntaxWarning)
|
||||||
try:
|
try:
|
||||||
compiled = compile(code, '<unknown>', 'exec')
|
compile(code, '<unknown>', 'exec')
|
||||||
except (SyntaxError, IndentationError) as e:
|
except (SyntaxError, IndentationError) as e:
|
||||||
wanted = e.__class__.__name__ + ': ' + e.msg
|
wanted = e.__class__.__name__ + ': ' + e.msg
|
||||||
line_nr = e.lineno
|
line_nr = e.lineno
|
||||||
@@ -114,19 +114,6 @@ def _get_actual_exception(code):
|
|||||||
# that are oddly enough not SyntaxErrors.
|
# that are oddly enough not SyntaxErrors.
|
||||||
wanted = 'SyntaxError: (value error) ' + str(e)
|
wanted = 'SyntaxError: (value error) ' + str(e)
|
||||||
line_nr = None
|
line_nr = None
|
||||||
else:
|
|
||||||
# In Python 3.12+, some invalid f-strings compile OK but
|
|
||||||
# only raise an exception when they are evaluated.
|
|
||||||
try:
|
|
||||||
eval(compiled)
|
|
||||||
except ValueError as e:
|
|
||||||
wanted = 'SyntaxError: (value error) ' + str(e)
|
|
||||||
line_nr = None
|
|
||||||
except (ImportError, ModuleNotFoundError):
|
|
||||||
# This comes from 'from .__future__ import whatever'
|
|
||||||
# in Python 3.13+
|
|
||||||
wanted = 'SyntaxError: future feature whatever is not defined'
|
|
||||||
line_nr = None
|
|
||||||
else:
|
else:
|
||||||
assert False, "The piece of code should raise an exception."
|
assert False, "The piece of code should raise an exception."
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user