mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
More Script fixture conversions in test_evaluate
This commit is contained in:
@@ -132,5 +132,5 @@ def cwd_tmpdir(monkeypatch, tmpdir):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def evaluator():
|
def evaluator(Script):
|
||||||
return jedi.Script('')._evaluator
|
return Script('')._evaluator
|
||||||
|
|||||||
@@ -2,11 +2,10 @@
|
|||||||
Tests ``from __future__ import absolute_import`` (only important for
|
Tests ``from __future__ import absolute_import`` (only important for
|
||||||
Python 2.X)
|
Python 2.X)
|
||||||
"""
|
"""
|
||||||
import jedi
|
|
||||||
from .. import helpers
|
from .. import helpers
|
||||||
|
|
||||||
|
|
||||||
@helpers.cwd_at("test/test_evaluate/absolute_import")
|
@helpers.cwd_at("test/test_evaluate/absolute_import")
|
||||||
def test_can_complete_when_shadowing():
|
def test_can_complete_when_shadowing(Script):
|
||||||
script = jedi.Script(path="unittest.py")
|
script = Script(path="unittest.py")
|
||||||
assert script.completions()
|
assert script.completions()
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
import jedi
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif('sys.version_info[0] < 3')
|
def test_simple_annotations(Script, environment):
|
||||||
def test_simple_annotations():
|
|
||||||
"""
|
"""
|
||||||
Annotations only exist in Python 3.
|
Annotations only exist in Python 3.
|
||||||
If annotations adhere to PEP-0484, we use them (they override inference),
|
If annotations adhere to PEP-0484, we use them (they override inference),
|
||||||
else they are parsed but ignored
|
else they are parsed but ignored
|
||||||
"""
|
"""
|
||||||
|
if environment.version_info.major == 2:
|
||||||
|
pytest.skip()
|
||||||
|
|
||||||
source = dedent("""\
|
source = dedent("""\
|
||||||
def annot(a:3):
|
def annot(a:3):
|
||||||
@@ -18,7 +18,7 @@ def test_simple_annotations():
|
|||||||
|
|
||||||
annot('')""")
|
annot('')""")
|
||||||
|
|
||||||
assert [d.name for d in jedi.Script(source, ).goto_definitions()] == ['str']
|
assert [d.name for d in Script(source).goto_definitions()] == ['str']
|
||||||
|
|
||||||
source = dedent("""\
|
source = dedent("""\
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ def test_simple_annotations():
|
|||||||
return a
|
return a
|
||||||
|
|
||||||
annot_ret('')""")
|
annot_ret('')""")
|
||||||
assert [d.name for d in jedi.Script(source, ).goto_definitions()] == ['str']
|
assert [d.name for d in Script(source).goto_definitions()] == ['str']
|
||||||
|
|
||||||
source = dedent("""\
|
source = dedent("""\
|
||||||
def annot(a:int):
|
def annot(a:int):
|
||||||
@@ -34,10 +34,9 @@ def test_simple_annotations():
|
|||||||
|
|
||||||
annot('')""")
|
annot('')""")
|
||||||
|
|
||||||
assert [d.name for d in jedi.Script(source, ).goto_definitions()] == ['int']
|
assert [d.name for d in Script(source).goto_definitions()] == ['int']
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif('sys.version_info[0] < 3')
|
|
||||||
@pytest.mark.parametrize('reference', [
|
@pytest.mark.parametrize('reference', [
|
||||||
'assert 1',
|
'assert 1',
|
||||||
'1',
|
'1',
|
||||||
@@ -45,16 +44,21 @@ def test_simple_annotations():
|
|||||||
'1, 2',
|
'1, 2',
|
||||||
r'1\n'
|
r'1\n'
|
||||||
])
|
])
|
||||||
def test_illegal_forward_references(reference):
|
def test_illegal_forward_references(Script, environment, reference):
|
||||||
|
if environment.version_info.major == 2:
|
||||||
|
pytest.skip()
|
||||||
|
|
||||||
source = 'def foo(bar: "%s"): bar' % reference
|
source = 'def foo(bar: "%s"): bar' % reference
|
||||||
|
|
||||||
assert not jedi.Script(source).goto_definitions()
|
assert not Script(source).goto_definitions()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif('sys.version_info[0] < 3')
|
def test_lambda_forward_references(Script, environment):
|
||||||
def test_lambda_forward_references():
|
if environment.version_info.major == 2:
|
||||||
|
pytest.skip()
|
||||||
|
|
||||||
source = 'def foo(bar: "lambda: 3"): bar'
|
source = 'def foo(bar: "lambda: 3"): bar'
|
||||||
|
|
||||||
# For now just receiving the 3 is ok. I'm doubting that this is what we
|
# For now just receiving the 3 is ok. I'm doubting that this is what we
|
||||||
# want. We also execute functions. Should we only execute classes?
|
# want. We also execute functions. Should we only execute classes?
|
||||||
assert jedi.Script(source).goto_definitions()
|
assert Script(source).goto_definitions()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
from jedi import Script
|
from jedi._compatibility import force_unicode
|
||||||
from jedi.evaluate.sys_path import (_get_parent_dir_with_file,
|
from jedi.evaluate.sys_path import (_get_parent_dir_with_file,
|
||||||
_get_buildout_script_paths,
|
_get_buildout_script_paths,
|
||||||
check_sys_path_modifications)
|
check_sys_path_modifications)
|
||||||
@@ -9,7 +9,7 @@ from jedi.evaluate.sys_path import (_get_parent_dir_with_file,
|
|||||||
from ..helpers import cwd_at
|
from ..helpers import cwd_at
|
||||||
|
|
||||||
|
|
||||||
def check_module_test(code):
|
def check_module_test(Script, code):
|
||||||
module_context = Script(code)._get_module()
|
module_context = Script(code)._get_module()
|
||||||
return check_sys_path_modifications(module_context)
|
return check_sys_path_modifications(module_context)
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ def test_buildout_detection():
|
|||||||
assert scripts[0] == appdir_path
|
assert scripts[0] == appdir_path
|
||||||
|
|
||||||
|
|
||||||
def test_append_on_non_sys_path():
|
def test_append_on_non_sys_path(Script):
|
||||||
code = dedent("""
|
code = dedent("""
|
||||||
class Dummy(object):
|
class Dummy(object):
|
||||||
path = []
|
path = []
|
||||||
@@ -40,24 +40,24 @@ def test_append_on_non_sys_path():
|
|||||||
d.path.append('foo')"""
|
d.path.append('foo')"""
|
||||||
)
|
)
|
||||||
|
|
||||||
paths = check_module_test(code)
|
paths = check_module_test(Script, code)
|
||||||
assert not paths
|
assert not paths
|
||||||
assert 'foo' not in paths
|
assert 'foo' not in paths
|
||||||
|
|
||||||
|
|
||||||
def test_path_from_invalid_sys_path_assignment():
|
def test_path_from_invalid_sys_path_assignment(Script):
|
||||||
code = dedent("""
|
code = dedent("""
|
||||||
import sys
|
import sys
|
||||||
sys.path = 'invalid'"""
|
sys.path = 'invalid'"""
|
||||||
)
|
)
|
||||||
|
|
||||||
paths = check_module_test(code)
|
paths = check_module_test(Script, code)
|
||||||
assert not paths
|
assert not paths
|
||||||
assert 'invalid' not in paths
|
assert 'invalid' not in paths
|
||||||
|
|
||||||
|
|
||||||
@cwd_at('test/test_evaluate/buildout_project/src/proj_name/')
|
@cwd_at('test/test_evaluate/buildout_project/src/proj_name/')
|
||||||
def test_sys_path_with_modifications():
|
def test_sys_path_with_modifications(Script):
|
||||||
code = dedent("""
|
code = dedent("""
|
||||||
import os
|
import os
|
||||||
""")
|
""")
|
||||||
@@ -67,7 +67,7 @@ def test_sys_path_with_modifications():
|
|||||||
assert '/tmp/.buildout/eggs/important_package.egg' in paths
|
assert '/tmp/.buildout/eggs/important_package.egg' in paths
|
||||||
|
|
||||||
|
|
||||||
def test_path_from_sys_path_assignment():
|
def test_path_from_sys_path_assignment(Script):
|
||||||
code = dedent("""
|
code = dedent("""
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
@@ -85,6 +85,7 @@ def test_path_from_sys_path_assignment():
|
|||||||
sys.exit(important_package.main())"""
|
sys.exit(important_package.main())"""
|
||||||
)
|
)
|
||||||
|
|
||||||
paths = check_module_test(code)
|
paths = check_module_test(Script, code)
|
||||||
|
paths = list(map(force_unicode, paths))
|
||||||
assert 1 not in paths
|
assert 1 not in paths
|
||||||
assert '/home/test/.buildout/eggs/important_package.egg' in paths
|
assert '/home/test/.buildout/eggs/important_package.egg' in paths
|
||||||
|
|||||||
@@ -1,16 +1,7 @@
|
|||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
import parso
|
|
||||||
|
|
||||||
from jedi._compatibility import builtins, is_py3
|
|
||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
from jedi.evaluate.context import instance
|
from jedi.evaluate.context import instance
|
||||||
from jedi.evaluate.context.function import FunctionContext
|
|
||||||
from jedi.evaluate import Evaluator
|
|
||||||
from jedi.evaluate.project import Project
|
|
||||||
from jedi.parser_utils import clean_scope_docstring
|
|
||||||
from jedi.api import interpreter
|
|
||||||
from jedi import Script
|
|
||||||
|
|
||||||
|
|
||||||
def test_simple(evaluator):
|
def test_simple(evaluator):
|
||||||
@@ -55,14 +46,14 @@ def test_doc(evaluator):
|
|||||||
assert obj.py__doc__() == ''
|
assert obj.py__doc__() == ''
|
||||||
|
|
||||||
|
|
||||||
def test_string_literals():
|
def test_string_literals(Script, environment):
|
||||||
def typ(string):
|
def typ(string):
|
||||||
d = Script("a = %s; a" % string).goto_definitions()[0]
|
d = Script("a = %s; a" % string).goto_definitions()[0]
|
||||||
return d.name
|
return d.name
|
||||||
|
|
||||||
assert typ('""') == 'str'
|
assert typ('""') == 'str'
|
||||||
assert typ('r""') == 'str'
|
assert typ('r""') == 'str'
|
||||||
if is_py3:
|
if environment.version_info.major > 2:
|
||||||
assert typ('br""') == 'bytes'
|
assert typ('br""') == 'bytes'
|
||||||
assert typ('b""') == 'bytes'
|
assert typ('b""') == 'bytes'
|
||||||
assert typ('u""') == 'str'
|
assert typ('u""') == 'str'
|
||||||
@@ -71,7 +62,7 @@ def test_string_literals():
|
|||||||
assert typ('u""') == 'unicode'
|
assert typ('u""') == 'unicode'
|
||||||
|
|
||||||
|
|
||||||
def test_method_completion():
|
def test_method_completion(Script, environment):
|
||||||
code = dedent('''
|
code = dedent('''
|
||||||
class Foo:
|
class Foo:
|
||||||
def bar(self):
|
def bar(self):
|
||||||
@@ -79,18 +70,18 @@ def test_method_completion():
|
|||||||
|
|
||||||
foo = Foo()
|
foo = Foo()
|
||||||
foo.bar.__func__''')
|
foo.bar.__func__''')
|
||||||
if is_py3:
|
if environment.version_info.major > 2:
|
||||||
result = []
|
result = []
|
||||||
else:
|
else:
|
||||||
result = ['__func__']
|
result = ['__func__']
|
||||||
assert [c.name for c in Script(code).completions()] == result
|
assert [c.name for c in Script(code).completions()] == result
|
||||||
|
|
||||||
|
|
||||||
def test_time_docstring():
|
def test_time_docstring(Script):
|
||||||
import time
|
import time
|
||||||
comp, = Script('import time\ntime.sleep').completions()
|
comp, = Script('import time\ntime.sleep').completions()
|
||||||
assert comp.docstring() == time.sleep.__doc__
|
assert comp.docstring() == time.sleep.__doc__
|
||||||
|
|
||||||
|
|
||||||
def test_dict_values():
|
def test_dict_values(Script):
|
||||||
assert Script('import sys\nsys.modules["alshdb;lasdhf"]').goto_definitions()
|
assert Script('import sys\nsys.modules["alshdb;lasdhf"]').goto_definitions()
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
from jedi import Script
|
def test_module_attributes(Script):
|
||||||
|
|
||||||
|
|
||||||
def test_module_attributes():
|
|
||||||
def_, = Script('__name__').completions()
|
def_, = Script('__name__').completions()
|
||||||
assert def_.name == '__name__'
|
assert def_.name == '__name__'
|
||||||
assert def_.line == None
|
assert def_.line == None
|
||||||
|
|||||||
Reference in New Issue
Block a user