mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-07 13:24:39 +08:00
Move some code around in tests.
This commit is contained in:
@@ -51,6 +51,33 @@ class X():
|
||||
nonlocal a
|
||||
|
||||
|
||||
def c():
|
||||
class X():
|
||||
nonlocal a
|
||||
|
||||
|
||||
def x():
|
||||
a = 3
|
||||
|
||||
def y():
|
||||
nonlocal a
|
||||
|
||||
|
||||
def x():
|
||||
def y():
|
||||
nonlocal a
|
||||
|
||||
a = 3
|
||||
|
||||
|
||||
def x():
|
||||
a = 3
|
||||
|
||||
def y():
|
||||
class z():
|
||||
nonlocal a
|
||||
|
||||
|
||||
a = *args, *args
|
||||
error[(*args, *args)] = 3
|
||||
*args, *args
|
||||
|
||||
@@ -9,54 +9,8 @@ import pytest
|
||||
import parso
|
||||
from parso.python.normalizer import ErrorFinderConfig
|
||||
|
||||
def _get_error_list(code, version=None):
|
||||
tree = parso.parse(code, version=version)
|
||||
config = ErrorFinderConfig()
|
||||
return list(tree._get_normalizer_issues(config))
|
||||
|
||||
|
||||
def assert_comparison(code, error_code, positions):
|
||||
errors = [(error.start_pos, error.code) for error in _get_error_list(code)]
|
||||
assert [(pos, error_code) for pos in positions] == errors
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('code', 'positions'), [
|
||||
('1 +', [(1, 3)]),
|
||||
('1 +\n', [(1, 3)]),
|
||||
('1 +\n2 +', [(1, 3), (2, 3)]),
|
||||
('x + 2', []),
|
||||
('[\n', [(2, 0)]),
|
||||
('[\ndef x(): pass', [(2, 0)]),
|
||||
('[\nif 1: pass', [(2, 0)]),
|
||||
('1+?', [(1, 2)]),
|
||||
('?', [(1, 0)]),
|
||||
('??', [(1, 0)]),
|
||||
('? ?', [(1, 0)]),
|
||||
('?\n?', [(1, 0), (2, 0)]),
|
||||
('? * ?', [(1, 0)]),
|
||||
('1 + * * 2', [(1, 4)]),
|
||||
('?\n1\n?', [(1, 0), (3, 0)]),
|
||||
]
|
||||
)
|
||||
def test_syntax_errors(code, positions):
|
||||
assert_comparison(code, 901, positions)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('code', 'positions'), [
|
||||
(' 1', [(1, 0)]),
|
||||
('def x():\n 1\n 2', [(3, 0)]),
|
||||
('def x():\n 1\n 2', [(3, 0)]),
|
||||
('def x():\n1', [(2, 0)]),
|
||||
]
|
||||
)
|
||||
def test_indentation_errors(code, positions):
|
||||
assert_comparison(code, 903, positions)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'code', [
|
||||
FAILING_EXAMPLES = [
|
||||
'1 +',
|
||||
'?',
|
||||
# Python/compile.c
|
||||
@@ -224,6 +178,8 @@ def test_indentation_errors(code, positions):
|
||||
global a
|
||||
nonlocal a
|
||||
'''),
|
||||
# Missing binding of nonlocal
|
||||
|
||||
|
||||
|
||||
# IndentationError
|
||||
@@ -232,7 +188,54 @@ def test_indentation_errors(code, positions):
|
||||
'def x():\n 1\n 2',
|
||||
'if 1:\nfoo',
|
||||
]
|
||||
|
||||
def _get_error_list(code, version=None):
|
||||
tree = parso.parse(code, version=version)
|
||||
config = ErrorFinderConfig()
|
||||
return list(tree._get_normalizer_issues(config))
|
||||
|
||||
|
||||
def assert_comparison(code, error_code, positions):
|
||||
errors = [(error.start_pos, error.code) for error in _get_error_list(code)]
|
||||
assert [(pos, error_code) for pos in positions] == errors
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('code', 'positions'), [
|
||||
('1 +', [(1, 3)]),
|
||||
('1 +\n', [(1, 3)]),
|
||||
('1 +\n2 +', [(1, 3), (2, 3)]),
|
||||
('x + 2', []),
|
||||
('[\n', [(2, 0)]),
|
||||
('[\ndef x(): pass', [(2, 0)]),
|
||||
('[\nif 1: pass', [(2, 0)]),
|
||||
('1+?', [(1, 2)]),
|
||||
('?', [(1, 0)]),
|
||||
('??', [(1, 0)]),
|
||||
('? ?', [(1, 0)]),
|
||||
('?\n?', [(1, 0), (2, 0)]),
|
||||
('? * ?', [(1, 0)]),
|
||||
('1 + * * 2', [(1, 4)]),
|
||||
('?\n1\n?', [(1, 0), (3, 0)]),
|
||||
]
|
||||
)
|
||||
def test_syntax_errors(code, positions):
|
||||
assert_comparison(code, 901, positions)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('code', 'positions'), [
|
||||
(' 1', [(1, 0)]),
|
||||
('def x():\n 1\n 2', [(3, 0)]),
|
||||
('def x():\n 1\n 2', [(3, 0)]),
|
||||
('def x():\n1', [(2, 0)]),
|
||||
]
|
||||
)
|
||||
def test_indentation_errors(code, positions):
|
||||
assert_comparison(code, 903, positions)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('code', FAILING_EXAMPLES)
|
||||
def test_python_exception_matches(code):
|
||||
wanted, line_nr = _get_actual_exception(code)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user