File: test_settings.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 (39 lines) | stat: -rw-r--r-- 1,179 bytes parent folder | download | duplicates (2)
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
import pytest

from jedi import settings
from jedi.inference.compiled import CompiledValueName
from jedi.inference.compiled.value import CompiledModule


@pytest.fixture()
def auto_import_json(monkeypatch):
    monkeypatch.setattr(settings, 'auto_import_modules', ['json'])


def test_base_auto_import_modules(auto_import_json, Script):
    loads, = Script('import json; json.loads').infer()
    assert isinstance(loads._name, CompiledValueName)
    value, = loads._name.infer()
    assert isinstance(value.parent_context._value, CompiledModule)


def test_auto_import_modules_imports(auto_import_json, Script):
    main, = Script('from json import tool; tool.main').infer()
    assert isinstance(main._name, CompiledValueName)


def test_cropped_file_size(monkeypatch, get_names, Script):
    code = 'class Foo(): pass\n'
    monkeypatch.setattr(
        settings,
        '_cropped_file_size',
        len(code)
    )

    foo, = get_names(code + code)
    assert foo.line == 1

    # It should just not crash if we are outside of the cropped range.
    script = Script(code + code + 'Foo')
    assert not script.infer()
    assert 'Foo' in [c.name for c in script.complete()]