Debian Codegraph @

test/test_settings.py

raw symbols SCIP
1 import pytest
2
3 from jedi import settings
4 from jedi.inference.compiled import CompiledValueName
5 from jedi.inference.compiled.value import CompiledModule
6
7
8 @pytest.fixture()
9 def auto_import_json(monkeypatch):
10 monkeypatch.setattr(settings, 'auto_import_modules', ['json'])
11
12
13 def test_base_auto_import_modules(auto_import_json, Script):
14 loads, = Script('import json; json.loads').infer()
15 assert isinstance(loads._name, CompiledValueName)
16 value, = loads._name.infer()
17 assert isinstance(value.parent_context._value, CompiledModule)
18
19
20 def test_auto_import_modules_imports(auto_import_json, Script):
21 main, = Script('from json import tool; tool.main').infer()
22 assert isinstance(main._name, CompiledValueName)
23
24
25 def test_cropped_file_size(monkeypatch, get_names, Script):
26 code = 'class Foo(): pass\n'
27 monkeypatch.setattr(
28 settings,
29 '_cropped_file_size',
30 len(code)
31 )
32
33 foo, = get_names(code + code)
34 assert foo.line == 1
35
36 # It should just not crash if we are outside of the cropped range.
37 script = Script(code + code + 'Foo')
38 assert not script.infer()
39 assert 'Foo' in [c.name for c in script.complete()]