File: test_basic.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 (92 lines) | stat: -rw-r--r-- 1,914 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from textwrap import dedent

import pytest
from parso import parse


def test_form_feed_characters(Script):
    s = "\f\nclass Test(object):\n    pass"
    Script(s).get_signatures(line=2, column=18)


def check_p(src):
    module_node = parse(src)
    assert src == module_node.get_code()
    return module_node


def test_if(Script):
    src = dedent('''\
    def func():
        x = 3
        if x:
            def y():
                return x
        return y()

    func()
    ''')

    # Two parsers needed, one for pass and one for the function.
    check_p(src)
    assert [d.name for d in Script(src).infer(8, 6)] == ['int']


def test_class_and_if(Script):
    src = dedent("""\
    class V:
        def __init__(self):
            pass

        if 1:
            c = 3

    def a_func():
        return 1

    # COMMENT
    a_func()""")
    check_p(src)
    assert [d.name for d in Script(src).infer()] == ['int']


def test_add_to_end(Script):
    """
    The diff parser doesn't parse everything again. It just updates with the
    help of caches, this is an example that didn't work.
    """

    a = dedent("""\
    class Abc():
        def abc(self):
            self.x = 3

    class Two(Abc):
        def g(self):
            self
    """)      # ^ here is the first completion

    b = "    def h(self):\n" \
        "        self."

    def complete(code, line=None, column=None):
        script = Script(code, path='example.py')
        assert script.complete(line, column)

    complete(a, 7, 12)
    complete(a + b)

    a = a[:-1] + '.\n'
    complete(a, 7, 13)
    complete(a + b)


def test_tokenizer_with_string_literal_backslash(Script):
    c = Script("statement = u'foo\\\n'; statement").infer()
    assert c[0]._name._value.get_safe_value() == 'foo'


def test_ellipsis_without_getitem(Script, environment):
    def_, = Script('x=...;x').infer()

    assert def_.name == 'ellipsis'