mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-08 13:45:01 +08:00
Move some tests a bit around.
This commit is contained in:
@@ -168,6 +168,10 @@ class Context(object):
|
|||||||
if name.is_definition():
|
if name.is_definition():
|
||||||
if parent.type == 'expr_stmt' \
|
if parent.type == 'expr_stmt' \
|
||||||
and parent.children[1].type == 'annassign':
|
and parent.children[1].type == 'annassign':
|
||||||
|
if found_global_or_nonlocal:
|
||||||
|
# If it's after the global the error seems to be
|
||||||
|
# placed there.
|
||||||
|
base_name = name
|
||||||
raise_("annotated name '%s' can't be %s")
|
raise_("annotated name '%s' can't be %s")
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -71,7 +71,6 @@ def test_indentation_errors(code, positions):
|
|||||||
'break',
|
'break',
|
||||||
'return',
|
'return',
|
||||||
'yield',
|
'yield',
|
||||||
'try: pass\nexcept: pass\nexcept X: pass',
|
|
||||||
|
|
||||||
# SyntaxError from Python/ast.c
|
# SyntaxError from Python/ast.c
|
||||||
'f(x for x in bar, 1)',
|
'f(x for x in bar, 1)',
|
||||||
@@ -235,10 +234,23 @@ def test_indentation_errors(code, positions):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_python_exception_matches(code):
|
def test_python_exception_matches(code):
|
||||||
|
wanted, line_nr = _get_actual_exception(code)
|
||||||
|
|
||||||
|
errors = _get_error_list(code)
|
||||||
|
actual = None
|
||||||
|
if errors:
|
||||||
|
error, = errors
|
||||||
|
actual = error.message
|
||||||
|
assert wanted == actual
|
||||||
|
assert line_nr == error.start_pos[0]
|
||||||
|
|
||||||
|
|
||||||
|
def _get_actual_exception(code):
|
||||||
try:
|
try:
|
||||||
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
|
||||||
else:
|
else:
|
||||||
assert False, "The piece of code should raise an exception."
|
assert False, "The piece of code should raise an exception."
|
||||||
|
|
||||||
@@ -246,12 +258,19 @@ def test_python_exception_matches(code):
|
|||||||
# Python 2.6 has a bit different error messages here, so skip it.
|
# Python 2.6 has a bit different error messages here, so skip it.
|
||||||
if sys.version_info[:2] == (2, 6) and wanted == 'SyntaxError: unexpected EOF while parsing':
|
if sys.version_info[:2] == (2, 6) and wanted == 'SyntaxError: unexpected EOF while parsing':
|
||||||
wanted = 'SyntaxError: invalid syntax'
|
wanted = 'SyntaxError: invalid syntax'
|
||||||
|
return wanted, line_nr
|
||||||
|
|
||||||
errors = _get_error_list(code)
|
|
||||||
actual = None
|
def test_default_except_error_postition():
|
||||||
if errors:
|
# For this error the position seemed to be one line off, but that doesn't
|
||||||
actual = errors[0].message
|
# really matter.
|
||||||
assert wanted == actual
|
code = 'try: pass\nexcept: pass\nexcept X: pass'
|
||||||
|
wanted, line_nr = _get_actual_exception(code)
|
||||||
|
error, = _get_error_list(code)
|
||||||
|
assert wanted == error.message
|
||||||
|
assert line_nr != error.start_pos[0]
|
||||||
|
# I think this is the better position.
|
||||||
|
assert error.start_pos[0] == 2
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|||||||
Reference in New Issue
Block a user