forked from VimPlug/jedi
Merge branch 'project'
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
from os.path import join
|
||||
from itertools import chain
|
||||
from functools import partial
|
||||
|
||||
import jedi
|
||||
from ..helpers import cwd_at
|
||||
from ..helpers import test_dir
|
||||
|
||||
|
||||
def test_import_empty(Script):
|
||||
@@ -47,8 +49,8 @@ def test_follow_import_incomplete(Script, environment):
|
||||
assert alias == ['module']
|
||||
|
||||
|
||||
@cwd_at('test/completion/import_tree')
|
||||
def test_follow_definition_nested_import(Script):
|
||||
Script = partial(Script, project=jedi.Project(join(test_dir, 'completion', 'import_tree')))
|
||||
types = check_follow_definition_types(Script, "import pkg.mod1; pkg")
|
||||
assert types == ['module']
|
||||
|
||||
|
||||
@@ -129,10 +129,11 @@ def test_completion_docstring(Script, jedi_path):
|
||||
Jedi should follow imports in certain conditions
|
||||
"""
|
||||
def docstr(src, result):
|
||||
c = Script(src, sys_path=[jedi_path]).complete()[0]
|
||||
c = Script(src, project=project).complete()[0]
|
||||
assert c.docstring(raw=True, fast=False) == cleandoc(result)
|
||||
|
||||
c = Script('import jedi\njed', sys_path=[jedi_path]).complete()[0]
|
||||
project = jedi.Project('.', sys_path=[jedi_path])
|
||||
c = Script('import jedi\njed', project=project).complete()[0]
|
||||
assert c.docstring(fast=False) == cleandoc(jedi_doc)
|
||||
|
||||
docstr('import jedi\njedi.Scr', cleandoc(jedi.Script.__doc__))
|
||||
|
||||
@@ -97,9 +97,10 @@ def test_sub_module(Script, jedi_path):
|
||||
path.
|
||||
"""
|
||||
sys_path = [jedi_path]
|
||||
defs = Script('from jedi.api import classes; classes', sys_path=sys_path).infer()
|
||||
project = jedi.Project('.', sys_path=sys_path)
|
||||
defs = Script('from jedi.api import classes; classes', project=project).infer()
|
||||
assert [d.full_name for d in defs] == ['jedi.api.classes']
|
||||
defs = Script('import jedi.api; jedi.api', sys_path=sys_path).infer()
|
||||
defs = Script('import jedi.api; jedi.api', project=project).infer()
|
||||
assert [d.full_name for d in defs] == ['jedi.api']
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ Tests for `api.names`.
|
||||
|
||||
from textwrap import dedent
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def _assert_definition_names(definitions, names):
|
||||
assert [d.name for d in definitions] == names
|
||||
@@ -167,3 +169,23 @@ def test_no_error(get_names):
|
||||
assert b.name == 'b'
|
||||
assert a20.name == 'a'
|
||||
assert a20.goto() == [a20]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'code, index, is_side_effect', [
|
||||
('x', 0, False),
|
||||
('x.x', 0, False),
|
||||
('x.x', 1, False),
|
||||
('x.x = 3', 0, False),
|
||||
('x.x = 3', 1, True),
|
||||
('def x(x): x.x = 3', 1, False),
|
||||
('def x(x): x.x = 3', 3, True),
|
||||
('import sys; sys.path', 0, False),
|
||||
('import sys; sys.path', 1, False),
|
||||
('import sys; sys.path', 2, False),
|
||||
('import sys; sys.path = []', 2, True),
|
||||
]
|
||||
)
|
||||
def test_is_side_effect(get_names, code, index, is_side_effect):
|
||||
names = get_names(code, references=True, all_scopes=True)
|
||||
assert names[index].is_side_effect() == is_side_effect
|
||||
@@ -2,6 +2,7 @@ import os
|
||||
|
||||
from ..helpers import get_example_dir, set_cwd, root_dir
|
||||
from jedi import Interpreter
|
||||
from jedi.api import Project, get_default_project
|
||||
|
||||
|
||||
def test_django_default_project(Script):
|
||||
@@ -22,3 +23,18 @@ def test_interpreter_project_path():
|
||||
with set_cwd(dir):
|
||||
project = Interpreter('', [locals()])._inference_state.project
|
||||
assert project._path == dir
|
||||
|
||||
|
||||
def test_added_sys_path(inference_state):
|
||||
project = get_default_project()
|
||||
p = '/some_random_path'
|
||||
project.added_sys_path = [p]
|
||||
assert p in project._get_sys_path(inference_state)
|
||||
|
||||
|
||||
def test_load_save_project(tmpdir):
|
||||
project = Project(tmpdir.strpath, added_sys_path=['/foo'])
|
||||
project.save()
|
||||
|
||||
loaded = Project.load(tmpdir.strpath)
|
||||
assert loaded.added_sys_path == ['/foo']
|
||||
|
||||
@@ -4,11 +4,9 @@ import pytest
|
||||
|
||||
from jedi import api
|
||||
from jedi.inference import imports
|
||||
from ..helpers import cwd_at
|
||||
|
||||
|
||||
@pytest.mark.skipif('True', reason='Skip for now, test case is not really supported.')
|
||||
@cwd_at('jedi')
|
||||
def test_add_dynamic_mods(Script):
|
||||
fname = '__main__.py'
|
||||
api.settings.additional_dynamic_modules = [fname]
|
||||
|
||||
54
test/test_api/test_syntax_errors.py
Normal file
54
test/test_api/test_syntax_errors.py
Normal file
@@ -0,0 +1,54 @@
|
||||
"""
|
||||
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', [
|
||||
('?\n', 1, 0, 1, 1),
|
||||
('x %% y', 1, 3, 1, 4),
|
||||
('"""\n\n', 1, 0, 3, 0),
|
||||
('(1, 2\n', 2, 0, 2, 0),
|
||||
('foo(1, 2\ndef x(): pass', 2, 0, 2, 3),
|
||||
]
|
||||
)
|
||||
def test_simple_syntax_errors(Script, code, line, column, until_line, until_column):
|
||||
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
|
||||
|
||||
|
||||
@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
|
||||
@@ -3,6 +3,7 @@
|
||||
All character set and unicode related tests.
|
||||
"""
|
||||
from jedi._compatibility import u, unicode
|
||||
from jedi import Project
|
||||
|
||||
|
||||
def test_unicode_script(Script):
|
||||
@@ -70,7 +71,8 @@ def test_wrong_encoding(Script, tmpdir):
|
||||
# Use both latin-1 and utf-8 (a really broken file).
|
||||
x.write_binary(u'foobar = 1\nä'.encode('latin-1') + u'ä'.encode('utf-8'))
|
||||
|
||||
c, = Script('import x; x.foo', sys_path=[tmpdir.strpath]).complete()
|
||||
project = Project('.', sys_path=[tmpdir.strpath])
|
||||
c, = Script('import x; x.foo', project=project).complete()
|
||||
assert c.name == 'foobar'
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ def test_import_references(Script):
|
||||
def test_exclude_builtin_modules(Script):
|
||||
def get(include):
|
||||
from jedi.api.project import Project
|
||||
script = Script(source, _project=Project('', sys_path=[], smart_sys_path=False))
|
||||
script = Script(source, project=Project('', sys_path=[], smart_sys_path=False))
|
||||
references = script.get_references(column=8, include_builtins=include)
|
||||
return [(d.line, d.column) for d in references]
|
||||
source = '''import sys\nprint(sys.path)'''
|
||||
|
||||
Reference in New Issue
Block a user