mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Get rid of cwd modifications in tests
This commit is contained in:
@@ -6,15 +6,15 @@ Tests".
|
||||
import os
|
||||
|
||||
import pytest
|
||||
from jedi.file_io import FileIO, KnownContentFileIO
|
||||
|
||||
from jedi.file_io import FileIO, KnownContentFileIO
|
||||
from jedi._compatibility import find_module_py33, find_module
|
||||
from jedi.inference import compiled
|
||||
from jedi.inference import imports
|
||||
from jedi.api.project import Project
|
||||
from jedi.inference.gradual.conversion import _stub_to_python_value_set
|
||||
from jedi.inference.references import get_module_contexts_containing_name
|
||||
from ..helpers import cwd_at, get_example_dir, test_dir, root_dir
|
||||
from ..helpers import get_example_dir, test_dir, test_dir_project, root_dir
|
||||
|
||||
THIS_DIR = os.path.dirname(__file__)
|
||||
|
||||
@@ -112,19 +112,24 @@ def test_find_module_not_package_zipped(Script, inference_state, environment):
|
||||
assert is_package is False
|
||||
|
||||
|
||||
@cwd_at('test/examples/not_in_sys_path/pkg')
|
||||
def test_import_not_in_sys_path(Script):
|
||||
def test_import_not_in_sys_path(Script, environment):
|
||||
"""
|
||||
non-direct imports (not in sys.path)
|
||||
|
||||
This is in the end just a fallback.
|
||||
"""
|
||||
a = Script(path='module.py').infer(line=5)
|
||||
path = get_example_dir()
|
||||
module_path = os.path.join(path, 'not_in_sys_path', 'pkg', 'module.py')
|
||||
# This project tests the smart path option of Project. The sys_path is
|
||||
# explicitly given to make sure that the path is just dumb and only
|
||||
# includes non-folder dependencies.
|
||||
project = Project(path, sys_path=environment.get_sys_path())
|
||||
a = Script(path=module_path, project=project).infer(line=5)
|
||||
assert a[0].name == 'int'
|
||||
|
||||
a = Script(path='module.py').infer(line=6)
|
||||
a = Script(path=module_path, project=project).infer(line=6)
|
||||
assert a[0].name == 'str'
|
||||
a = Script(path='module.py').infer(line=7)
|
||||
a = Script(path=module_path, project=project).infer(line=7)
|
||||
assert a[0].name == 'str'
|
||||
|
||||
|
||||
@@ -150,10 +155,9 @@ def test_flask_ext(Script, code, name):
|
||||
assert name in [c.name for c in completions]
|
||||
|
||||
|
||||
@cwd_at('test/test_inference/')
|
||||
def test_not_importable_file(Script):
|
||||
src = 'import not_importable_file as x; x.'
|
||||
assert not Script(src, path='example.py').complete()
|
||||
assert not Script(src, path='example.py', project=test_dir_project).complete()
|
||||
|
||||
|
||||
def test_import_unique(Script):
|
||||
@@ -200,29 +204,28 @@ def test_goto_definition_on_import(Script):
|
||||
assert len(Script("import sys").infer(1, 8)) == 1
|
||||
|
||||
|
||||
@cwd_at('jedi')
|
||||
def test_complete_on_empty_import(Script):
|
||||
assert Script("from datetime import").complete()[0].name == 'import'
|
||||
def test_complete_on_empty_import(ScriptWithProject):
|
||||
assert ScriptWithProject("from datetime import").complete()[0].name == 'import'
|
||||
# should just list the files in the directory
|
||||
assert 10 < len(Script("from .", path='whatever.py').complete()) < 30
|
||||
assert 10 < len(ScriptWithProject("from .", path='whatever.py').complete()) < 30
|
||||
|
||||
# Global import
|
||||
assert len(Script("from . import", 'whatever.py').complete(1, 5)) > 30
|
||||
assert len(ScriptWithProject("from . import", 'whatever.py').complete(1, 5)) > 30
|
||||
# relative import
|
||||
assert 10 < len(Script("from . import", 'whatever.py').complete(1, 6)) < 30
|
||||
assert 10 < len(ScriptWithProject("from . import", 'whatever.py').complete(1, 6)) < 30
|
||||
|
||||
# Global import
|
||||
assert len(Script("from . import classes", 'whatever.py').complete(1, 5)) > 30
|
||||
assert len(ScriptWithProject("from . import classes", 'whatever.py').complete(1, 5)) > 30
|
||||
# relative import
|
||||
assert 10 < len(Script("from . import classes", 'whatever.py').complete(1, 6)) < 30
|
||||
assert 10 < len(ScriptWithProject("from . import classes", 'whatever.py').complete(1, 6)) < 30
|
||||
|
||||
wanted = {'ImportError', 'import', 'ImportWarning'}
|
||||
assert {c.name for c in Script("import").complete()} == wanted
|
||||
assert len(Script("import import", path='').complete()) > 0
|
||||
assert {c.name for c in ScriptWithProject("import").complete()} == wanted
|
||||
assert len(ScriptWithProject("import import", path='').complete()) > 0
|
||||
|
||||
# 111
|
||||
assert Script("from datetime import").complete()[0].name == 'import'
|
||||
assert Script("from datetime import ").complete()
|
||||
assert ScriptWithProject("from datetime import").complete()[0].name == 'import'
|
||||
assert ScriptWithProject("from datetime import ").complete()
|
||||
|
||||
|
||||
def test_imports_on_global_namespace_without_path(Script):
|
||||
@@ -394,9 +397,9 @@ def test_relative_imports_with_outside_paths(Script):
|
||||
assert not script.complete()
|
||||
|
||||
|
||||
@cwd_at('test/examples/issue1209/api/whatever/')
|
||||
def test_relative_imports_without_path(Script):
|
||||
project = Project('.', sys_path=[], smart_sys_path=False)
|
||||
path = get_example_dir('issue1209', 'api', 'whatever')
|
||||
project = Project(path, sys_path=[], smart_sys_path=False)
|
||||
script = Script("from . ", project=project)
|
||||
assert [c.name for c in script.complete()] == ['api_test1', 'import']
|
||||
|
||||
|
||||
Reference in New Issue
Block a user