File: test_syntax_errors.py

package info (click to toggle)
python-jedi 0.19.1%2Bds1-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,680 kB
  • sloc: python: 28,783; makefile: 172; ansic: 13
file content (55 lines) | stat: -rw-r--r-- 1,554 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
These tests test Jedi's Parso usage. Basically there's not a lot of tests here,
because we're just checking if the API works. Bugfixes should be done in parso,
mostly.
"""

from textwrap import dedent

import pytest


@pytest.mark.parametrize(
    'code, line, column, until_line, until_column, message', [
        ('?\n', 1, 0, 1, 1, 'SyntaxError: invalid syntax'),
        ('x %% y', 1, 3, 1, 4, 'SyntaxError: invalid syntax'),
        ('"""\n\n', 1, 0, 3, 0, 'SyntaxError: EOF while scanning triple-quoted string literal'),
        ('(1, 2\n', 2, 0, 2, 0, 'SyntaxError: invalid syntax'),
        ('foo(1, 2\ndef x(): pass', 2, 0, 2, 3, 'SyntaxError: invalid syntax'),
    ]
)
def test_simple_syntax_errors(Script, code, line, column, until_line, until_column, message):
    e, = Script(code).get_syntax_errors()
    assert e.line == line
    assert e.column == column
    assert e.until_line == until_line
    assert e.until_column == until_column
    assert e.get_message() == message


@pytest.mark.parametrize(
    'code', [
        'x % y',
        'def x(x): pass',
        'def x(x):\n pass',
    ]
)
def test_no_syntax_errors(Script, code):
    assert not Script(code).get_syntax_errors()


def test_multi_syntax_error(Script):
    code = dedent('''\
        def x():
        1
        def y()
        1 + 1
        1 *** 3
        ''')
    x, y, power = Script(code).get_syntax_errors()
    assert x.line == 2
    assert x.column == 0
    assert y.line == 3
    assert y.column == 7
    assert power.line == 5
    assert power.column == 4