Some tests that involved jedi were actually a bit wrong and only worked in certain environments.

This commit is contained in:
Dave Halter
2018-01-05 00:48:40 +01:00
parent 4d896892a3
commit db1a4415b3
4 changed files with 20 additions and 10 deletions

View File

@@ -110,3 +110,8 @@ def has_typing(environment):
script = jedi.Script('import typing', environment=environment)
return bool(script.goto_definitions())
@pytest.fixture(scope='session')
def jedi_path():
return os.path.dirname(__file__)

View File

@@ -5,6 +5,9 @@ import os
_d = os.path.dirname
_jedi_path = _d(_d(_d(_d(_d(__file__)))))
_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
# simply import something from a specific location.

View File

@@ -61,7 +61,6 @@ def test_basedefinition_type(Script, environment):
return definitions
for definition in make_definitions():
assert definition.type in ('module', 'class', 'instance', 'function',
'generator', 'statement', 'import', 'param')
@@ -115,16 +114,15 @@ def test_position_none_if_builtin(Script):
assert gotos[0].column is None
@cwd_at('.')
def test_completion_docstring(Script):
def test_completion_docstring(Script, jedi_path):
"""
Jedi should follow imports in certain conditions
"""
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)
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)
docstr('import jedi\njedi.Scr', cleandoc(jedi.Script.__doc__))

View File

@@ -18,7 +18,7 @@ import textwrap
import pytest
import jedi
from ..helpers import TestCase
from ..helpers import TestCase, cwd_at
class MixinTestFullName(object):
@@ -66,9 +66,12 @@ class TestFullDefinedName(TestCase):
"""
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):
definitions = jedi.names(textwrap.dedent(source))
definitions = jedi.names(textwrap.dedent(source), environment=self.environment)
full_names = [d.full_name for d in definitions]
self.assertEqual(full_names, desired)
@@ -87,14 +90,15 @@ class TestFullDefinedName(TestCase):
""", ['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
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']
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']