File: test_representation.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 (34 lines) | stat: -rw-r--r-- 1,014 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
from textwrap import dedent


def get_definition_and_inference_state(Script, source):
    first, = Script(dedent(source)).infer()
    return first._name._value, first._inference_state


def test_function_execution(Script):
    """
    We've been having an issue of a mutable list that was changed inside the
    function execution. Test if an execution always returns the same result.
    """

    s = """
    def x():
        return str()
    x"""
    func, inference_state = get_definition_and_inference_state(Script, s)
    # Now just use the internals of the result (easiest way to get a fully
    # usable function).
    # Should return the same result both times.
    assert len(func.execute_with_values()) == 1
    assert len(func.execute_with_values()) == 1


def test_class_mro(Script):
    s = """
    class X(object):
        pass
    X"""
    cls, inference_state = get_definition_and_inference_state(Script, s)
    mro = cls.py__mro__()
    assert [c.name.string_name for c in mro] == ['X', 'object']