forked from VimPlug/jedi
Some tests that involved jedi were actually a bit wrong and only worked in certain environments.
This commit is contained in:
@@ -110,3 +110,8 @@ def has_typing(environment):
|
|||||||
|
|
||||||
script = jedi.Script('import typing', environment=environment)
|
script = jedi.Script('import typing', environment=environment)
|
||||||
return bool(script.goto_definitions())
|
return bool(script.goto_definitions())
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='session')
|
||||||
|
def jedi_path():
|
||||||
|
return os.path.dirname(__file__)
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ import os
|
|||||||
_d = os.path.dirname
|
_d = os.path.dirname
|
||||||
_jedi_path = _d(_d(_d(_d(_d(__file__)))))
|
_jedi_path = _d(_d(_d(_d(_d(__file__)))))
|
||||||
_parso_path = sys.argv[1]
|
_parso_path = sys.argv[1]
|
||||||
|
# Remove the first entry, because it's simply a directory entry to this
|
||||||
|
# directory.
|
||||||
|
del sys.path[0]
|
||||||
|
|
||||||
# This is kind of stupid. We actually don't want to modify the sys path but
|
# This is kind of stupid. We actually don't want to modify the sys path but
|
||||||
# simply import something from a specific location.
|
# simply import something from a specific location.
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ def test_basedefinition_type(Script, environment):
|
|||||||
|
|
||||||
return definitions
|
return definitions
|
||||||
|
|
||||||
|
|
||||||
for definition in make_definitions():
|
for definition in make_definitions():
|
||||||
assert definition.type in ('module', 'class', 'instance', 'function',
|
assert definition.type in ('module', 'class', 'instance', 'function',
|
||||||
'generator', 'statement', 'import', 'param')
|
'generator', 'statement', 'import', 'param')
|
||||||
@@ -115,16 +114,15 @@ def test_position_none_if_builtin(Script):
|
|||||||
assert gotos[0].column is None
|
assert gotos[0].column is None
|
||||||
|
|
||||||
|
|
||||||
@cwd_at('.')
|
def test_completion_docstring(Script, jedi_path):
|
||||||
def test_completion_docstring(Script):
|
|
||||||
"""
|
"""
|
||||||
Jedi should follow imports in certain conditions
|
Jedi should follow imports in certain conditions
|
||||||
"""
|
"""
|
||||||
def docstr(src, result):
|
def docstr(src, result):
|
||||||
c = Script(src).completions()[0]
|
c = Script(src, sys_path=[jedi_path]).completions()[0]
|
||||||
assert c.docstring(raw=True, fast=False) == cleandoc(result)
|
assert c.docstring(raw=True, fast=False) == cleandoc(result)
|
||||||
|
|
||||||
c = Script('import jedi\njed').completions()[0]
|
c = Script('import jedi\njed', sys_path=[jedi_path]).completions()[0]
|
||||||
assert c.docstring(fast=False) == cleandoc(jedi_doc)
|
assert c.docstring(fast=False) == cleandoc(jedi_doc)
|
||||||
|
|
||||||
docstr('import jedi\njedi.Scr', cleandoc(jedi.Script.__doc__))
|
docstr('import jedi\njedi.Scr', cleandoc(jedi.Script.__doc__))
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import textwrap
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import jedi
|
import jedi
|
||||||
from ..helpers import TestCase
|
from ..helpers import TestCase, cwd_at
|
||||||
|
|
||||||
|
|
||||||
class MixinTestFullName(object):
|
class MixinTestFullName(object):
|
||||||
@@ -66,9 +66,12 @@ class TestFullDefinedName(TestCase):
|
|||||||
"""
|
"""
|
||||||
Test combination of ``obj.full_name`` and ``jedi.defined_names``.
|
Test combination of ``obj.full_name`` and ``jedi.defined_names``.
|
||||||
"""
|
"""
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def init(self, environment):
|
||||||
|
self.environment = environment
|
||||||
|
|
||||||
def check(self, source, desired):
|
def check(self, source, desired):
|
||||||
definitions = jedi.names(textwrap.dedent(source))
|
definitions = jedi.names(textwrap.dedent(source), environment=self.environment)
|
||||||
full_names = [d.full_name for d in definitions]
|
full_names = [d.full_name for d in definitions]
|
||||||
self.assertEqual(full_names, desired)
|
self.assertEqual(full_names, desired)
|
||||||
|
|
||||||
@@ -87,14 +90,15 @@ class TestFullDefinedName(TestCase):
|
|||||||
""", ['os', 'os.path', 'os.path.join', 'os.path'])
|
""", ['os', 'os.path', 'os.path.join', 'os.path'])
|
||||||
|
|
||||||
|
|
||||||
def test_sub_module(Script):
|
def test_sub_module(Script, jedi_path):
|
||||||
"""
|
"""
|
||||||
``full_name needs to check sys.path to actually find it's real path module
|
``full_name needs to check sys.path to actually find it's real path module
|
||||||
path.
|
path.
|
||||||
"""
|
"""
|
||||||
defs = Script('from jedi.api import classes; classes').goto_definitions()
|
sys_path = [jedi_path]
|
||||||
|
defs = Script('from jedi.api import classes; classes', sys_path=sys_path).goto_definitions()
|
||||||
assert [d.full_name for d in defs] == ['jedi.api.classes']
|
assert [d.full_name for d in defs] == ['jedi.api.classes']
|
||||||
defs = Script('import jedi.api; jedi.api').goto_definitions()
|
defs = Script('import jedi.api; jedi.api', sys_path=sys_path).goto_definitions()
|
||||||
assert [d.full_name for d in defs] == ['jedi.api']
|
assert [d.full_name for d in defs] == ['jedi.api']
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user