mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +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
|
||||
def evaluator():
|
||||
return jedi.Script('')._evaluator
|
||||
def evaluator(Script):
|
||||
return Script('')._evaluator
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
Tests ``from __future__ import absolute_import`` (only important for
|
||||
Python 2.X)
|
||||
"""
|
||||
import jedi
|
||||
from .. import helpers
|
||||
|
||||
|
||||
@helpers.cwd_at("test/test_evaluate/absolute_import")
|
||||
def test_can_complete_when_shadowing():
|
||||
script = jedi.Script(path="unittest.py")
|
||||
def test_can_complete_when_shadowing(Script):
|
||||
script = Script(path="unittest.py")
|
||||
assert script.completions()
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
from textwrap import dedent
|
||||
|
||||
import jedi
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.skipif('sys.version_info[0] < 3')
|
||||
def test_simple_annotations():
|
||||
def test_simple_annotations(Script, environment):
|
||||
"""
|
||||
Annotations only exist in Python 3.
|
||||
If annotations adhere to PEP-0484, we use them (they override inference),
|
||||
else they are parsed but ignored
|
||||
"""
|
||||
if environment.version_info.major == 2:
|
||||
pytest.skip()
|
||||
|
||||
source = dedent("""\
|
||||
def annot(a:3):
|
||||
@@ -18,7 +18,7 @@ def test_simple_annotations():
|
||||
|
||||
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("""\
|
||||
|
||||
@@ -26,7 +26,7 @@ def test_simple_annotations():
|
||||
return a
|
||||
|
||||
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("""\
|
||||
def annot(a:int):
|
||||
@@ -34,10 +34,9 @@ def test_simple_annotations():
|
||||
|
||||
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', [
|
||||
'assert 1',
|
||||
'1',
|
||||
@@ -45,16 +44,21 @@ def test_simple_annotations():
|
||||
'1, 2',
|
||||
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
|
||||
|
||||
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():
|
||||
def test_lambda_forward_references(Script, environment):
|
||||
if environment.version_info.major == 2:
|
||||
pytest.skip()
|
||||
|
||||
source = 'def foo(bar: "lambda: 3"): bar'
|
||||
|
||||
# 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?
|
||||
assert jedi.Script(source).goto_definitions()
|
||||
assert Script(source).goto_definitions()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
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,
|
||||
_get_buildout_script_paths,
|
||||
check_sys_path_modifications)
|
||||
@@ -9,7 +9,7 @@ from jedi.evaluate.sys_path import (_get_parent_dir_with_file,
|
||||
from ..helpers import cwd_at
|
||||
|
||||
|
||||
def check_module_test(code):
|
||||
def check_module_test(Script, code):
|
||||
module_context = Script(code)._get_module()
|
||||
return check_sys_path_modifications(module_context)
|
||||
|
||||
@@ -31,7 +31,7 @@ def test_buildout_detection():
|
||||
assert scripts[0] == appdir_path
|
||||
|
||||
|
||||
def test_append_on_non_sys_path():
|
||||
def test_append_on_non_sys_path(Script):
|
||||
code = dedent("""
|
||||
class Dummy(object):
|
||||
path = []
|
||||
@@ -40,24 +40,24 @@ def test_append_on_non_sys_path():
|
||||
d.path.append('foo')"""
|
||||
)
|
||||
|
||||
paths = check_module_test(code)
|
||||
paths = check_module_test(Script, code)
|
||||
assert not 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("""
|
||||
import sys
|
||||
sys.path = 'invalid'"""
|
||||
)
|
||||
|
||||
paths = check_module_test(code)
|
||||
paths = check_module_test(Script, code)
|
||||
assert not paths
|
||||
assert 'invalid' not in paths
|
||||
|
||||
|
||||
@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("""
|
||||
import os
|
||||
""")
|
||||
@@ -67,7 +67,7 @@ def test_sys_path_with_modifications():
|
||||
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("""
|
||||
#!/usr/bin/python
|
||||
|
||||
@@ -85,6 +85,7 @@ def test_path_from_sys_path_assignment():
|
||||
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 '/home/test/.buildout/eggs/important_package.egg' in paths
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
from textwrap import dedent
|
||||
|
||||
import parso
|
||||
|
||||
from jedi._compatibility import builtins, is_py3
|
||||
from jedi.evaluate import compiled
|
||||
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):
|
||||
@@ -55,14 +46,14 @@ def test_doc(evaluator):
|
||||
assert obj.py__doc__() == ''
|
||||
|
||||
|
||||
def test_string_literals():
|
||||
def test_string_literals(Script, environment):
|
||||
def typ(string):
|
||||
d = Script("a = %s; a" % string).goto_definitions()[0]
|
||||
return d.name
|
||||
|
||||
assert typ('""') == 'str'
|
||||
assert typ('r""') == 'str'
|
||||
if is_py3:
|
||||
if environment.version_info.major > 2:
|
||||
assert typ('br""') == 'bytes'
|
||||
assert typ('b""') == 'bytes'
|
||||
assert typ('u""') == 'str'
|
||||
@@ -71,7 +62,7 @@ def test_string_literals():
|
||||
assert typ('u""') == 'unicode'
|
||||
|
||||
|
||||
def test_method_completion():
|
||||
def test_method_completion(Script, environment):
|
||||
code = dedent('''
|
||||
class Foo:
|
||||
def bar(self):
|
||||
@@ -79,18 +70,18 @@ def test_method_completion():
|
||||
|
||||
foo = Foo()
|
||||
foo.bar.__func__''')
|
||||
if is_py3:
|
||||
if environment.version_info.major > 2:
|
||||
result = []
|
||||
else:
|
||||
result = ['__func__']
|
||||
assert [c.name for c in Script(code).completions()] == result
|
||||
|
||||
|
||||
def test_time_docstring():
|
||||
def test_time_docstring(Script):
|
||||
import time
|
||||
comp, = Script('import time\ntime.sleep').completions()
|
||||
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()
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
from jedi import Script
|
||||
|
||||
|
||||
def test_module_attributes():
|
||||
def test_module_attributes(Script):
|
||||
def_, = Script('__name__').completions()
|
||||
assert def_.name == '__name__'
|
||||
assert def_.line == None
|
||||
|
||||
Reference in New Issue
Block a user