forked from VimPlug/jedi
Evaluator -> InferState
This commit is contained in:
@@ -13,8 +13,8 @@ sys.path.append('a' +* '/thirdparty')
|
||||
#? ['inference']
|
||||
import inference
|
||||
|
||||
#? ['evaluator_function_cache']
|
||||
inference.Evaluator_fu
|
||||
#? ['infer_state_function_cache']
|
||||
inference.infer_state_fu
|
||||
|
||||
# Those don't work because dirname and abspath are not properly understood.
|
||||
##? ['jedi_']
|
||||
|
||||
@@ -162,10 +162,10 @@ def cwd_tmpdir(monkeypatch, tmpdir):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def evaluator(Script):
|
||||
return Script('')._evaluator
|
||||
def infer_state(Script):
|
||||
return Script('')._infer_state
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def same_process_evaluator(Script):
|
||||
return Script('', environment=InterpreterEnvironment())._evaluator
|
||||
def same_process_infer_state(Script):
|
||||
return Script('', environment=InterpreterEnvironment())._infer_state
|
||||
|
||||
@@ -212,7 +212,7 @@ class IntegrationTestCase(object):
|
||||
|
||||
def run_goto_definitions(self, compare_cb, environment):
|
||||
script = self.script(environment)
|
||||
evaluator = script._evaluator
|
||||
infer_state = script._infer_state
|
||||
|
||||
def comparison(definition):
|
||||
suffix = '()' if definition.type == 'instance' else ''
|
||||
@@ -232,13 +232,13 @@ class IntegrationTestCase(object):
|
||||
user_context = user_context.get_function_execution()
|
||||
element.parent = user_context.tree_node
|
||||
results = convert_contexts(
|
||||
evaluator.infer_element(user_context, element),
|
||||
infer_state.infer_element(user_context, element),
|
||||
)
|
||||
if not results:
|
||||
raise Exception('Could not resolve %s on line %s'
|
||||
% (match.string, self.line_nr - 1))
|
||||
|
||||
should_be |= set(Definition(evaluator, r.name) for r in results)
|
||||
should_be |= set(Definition(infer_state, r.name) for r in results)
|
||||
debug.dbg('Finished getting types', color='YELLOW')
|
||||
|
||||
# Because the objects have different ids, `repr`, then compare.
|
||||
|
||||
@@ -42,10 +42,10 @@ def test_versions(version):
|
||||
assert env.get_sys_path()
|
||||
|
||||
|
||||
def test_load_module(evaluator):
|
||||
access_path = evaluator.compiled_subprocess.load_module(
|
||||
def test_load_module(infer_state):
|
||||
access_path = infer_state.compiled_subprocess.load_module(
|
||||
dotted_name=u'math',
|
||||
sys_path=evaluator.get_sys_path()
|
||||
sys_path=infer_state.get_sys_path()
|
||||
)
|
||||
name, access_handle = access_path.accesses[0]
|
||||
|
||||
@@ -55,31 +55,31 @@ def test_load_module(evaluator):
|
||||
access_handle.py__mro__()
|
||||
|
||||
|
||||
def test_error_in_environment(evaluator, Script, environment):
|
||||
def test_error_in_environment(infer_state, Script, environment):
|
||||
if isinstance(environment, InterpreterEnvironment):
|
||||
pytest.skip("We don't catch these errors at the moment.")
|
||||
|
||||
# Provoke an error to show how Jedi can recover from it.
|
||||
with pytest.raises(jedi.InternalError):
|
||||
evaluator.compiled_subprocess._test_raise_error(KeyboardInterrupt)
|
||||
infer_state.compiled_subprocess._test_raise_error(KeyboardInterrupt)
|
||||
# The second time it should raise an InternalError again.
|
||||
with pytest.raises(jedi.InternalError):
|
||||
evaluator.compiled_subprocess._test_raise_error(KeyboardInterrupt)
|
||||
infer_state.compiled_subprocess._test_raise_error(KeyboardInterrupt)
|
||||
# Jedi should still work.
|
||||
def_, = Script('str').goto_definitions()
|
||||
assert def_.name == 'str'
|
||||
|
||||
|
||||
def test_stdout_in_subprocess(evaluator, Script):
|
||||
evaluator.compiled_subprocess._test_print(stdout='.')
|
||||
def test_stdout_in_subprocess(infer_state, Script):
|
||||
infer_state.compiled_subprocess._test_print(stdout='.')
|
||||
Script('1').goto_definitions()
|
||||
|
||||
|
||||
def test_killed_subprocess(evaluator, Script, environment):
|
||||
def test_killed_subprocess(infer_state, Script, environment):
|
||||
if isinstance(environment, InterpreterEnvironment):
|
||||
pytest.skip("We cannot kill our own process")
|
||||
# Just kill the subprocess.
|
||||
evaluator.compiled_subprocess._compiled_subprocess._get_process().kill()
|
||||
infer_state.compiled_subprocess._compiled_subprocess._get_process().kill()
|
||||
# Since the process was terminated (and nobody knows about it) the first
|
||||
# Jedi call fails.
|
||||
with pytest.raises(jedi.InternalError):
|
||||
|
||||
@@ -13,12 +13,12 @@ def test_django_default_project(Script):
|
||||
)
|
||||
c, = script.completions()
|
||||
assert c.name == "SomeModel"
|
||||
assert script._evaluator.project._django is True
|
||||
assert script._infer_state.project._django is True
|
||||
|
||||
|
||||
def test_interpreter_project_path():
|
||||
# Run from anywhere it should be the cwd.
|
||||
dir = os.path.join(root_dir, 'test')
|
||||
with set_cwd(dir):
|
||||
project = Interpreter('', [locals()])._evaluator.project
|
||||
project = Interpreter('', [locals()])._infer_state.project
|
||||
assert project._path == dir
|
||||
|
||||
@@ -17,7 +17,7 @@ def test_add_dynamic_mods(Script):
|
||||
# Other fictional modules in another place in the fs.
|
||||
src2 = 'from .. import setup; setup.r(1)'
|
||||
script = Script(src1, path='../setup.py')
|
||||
imports.load_module(script._evaluator, os.path.abspath(fname), src2)
|
||||
imports.load_module(script._infer_state, os.path.abspath(fname), src2)
|
||||
result = script.goto_definitions()
|
||||
assert len(result) == 1
|
||||
assert result[0].description == 'class int'
|
||||
|
||||
@@ -63,7 +63,7 @@ def test_sys_path_with_modifications(Script):
|
||||
""")
|
||||
|
||||
path = os.path.abspath(os.path.join(os.curdir, 'module_name.py'))
|
||||
paths = Script(code, path=path)._evaluator.get_sys_path()
|
||||
paths = Script(code, path=path)._infer_state.get_sys_path()
|
||||
assert '/tmp/.buildout/eggs/important_package.egg' in paths
|
||||
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ from jedi.inference.compiled.access import DirectObjectAccess
|
||||
from jedi.inference.gradual.conversion import _stub_to_python_context_set
|
||||
|
||||
|
||||
def test_simple(evaluator, environment):
|
||||
obj = compiled.create_simple_object(evaluator, u'_str_')
|
||||
def test_simple(infer_state, environment):
|
||||
obj = compiled.create_simple_object(infer_state, u'_str_')
|
||||
upper, = obj.py__getattribute__(u'upper')
|
||||
objs = list(upper.execute_with_values())
|
||||
assert len(objs) == 1
|
||||
@@ -23,15 +23,15 @@ def test_simple(evaluator, environment):
|
||||
assert objs[0].name.string_name == expected
|
||||
|
||||
|
||||
def test_builtin_loading(evaluator):
|
||||
string, = evaluator.builtins_module.py__getattribute__(u'str')
|
||||
def test_builtin_loading(infer_state):
|
||||
string, = infer_state.builtins_module.py__getattribute__(u'str')
|
||||
from_name, = string.py__getattribute__(u'__init__')
|
||||
assert from_name.tree_node
|
||||
assert not from_name.py__doc__() # It's a stub
|
||||
|
||||
|
||||
def test_next_docstr(evaluator):
|
||||
next_ = compiled.builtin_from_name(evaluator, u'next')
|
||||
def test_next_docstr(infer_state):
|
||||
next_ = compiled.builtin_from_name(infer_state, u'next')
|
||||
assert next_.tree_node is not None
|
||||
assert next_.py__doc__() == '' # It's a stub
|
||||
for non_stub in _stub_to_python_context_set(next_):
|
||||
@@ -47,12 +47,12 @@ def test_parse_function_doc_illegal_docstr():
|
||||
assert ('', '') == compiled.context._parse_function_doc(docstr)
|
||||
|
||||
|
||||
def test_doc(evaluator):
|
||||
def test_doc(infer_state):
|
||||
"""
|
||||
Even CompiledObject docs always return empty docstrings - not None, that's
|
||||
just a Jedi API definition.
|
||||
"""
|
||||
str_ = compiled.create_simple_object(evaluator, u'')
|
||||
str_ = compiled.create_simple_object(infer_state, u'')
|
||||
# Equals `''.__getnewargs__`
|
||||
obj, = str_.py__getattribute__(u'__getnewargs__')
|
||||
assert obj.py__doc__() == ''
|
||||
@@ -103,7 +103,7 @@ def test_dict_values(Script, environment):
|
||||
def test_getitem_on_none(Script):
|
||||
script = Script('None[1j]')
|
||||
assert not script.goto_definitions()
|
||||
issue, = script._evaluator.analysis
|
||||
issue, = script._infer_state.analysis
|
||||
assert issue.name == 'type-error-not-subscriptable'
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ def _return_int():
|
||||
('ret_int', '_return_int', 'test.test_inference.test_compiled'),
|
||||
]
|
||||
)
|
||||
def test_parent_context(same_process_evaluator, attribute, expected_name, expected_parent):
|
||||
def test_parent_context(same_process_infer_state, attribute, expected_name, expected_parent):
|
||||
import decimal
|
||||
|
||||
class C:
|
||||
@@ -135,8 +135,8 @@ def test_parent_context(same_process_evaluator, attribute, expected_name, expect
|
||||
ret_int = _return_int
|
||||
|
||||
o = compiled.CompiledObject(
|
||||
same_process_evaluator,
|
||||
DirectObjectAccess(same_process_evaluator, C)
|
||||
same_process_infer_state,
|
||||
DirectObjectAccess(same_process_infer_state, C)
|
||||
)
|
||||
x, = o.py__getattribute__(attribute)
|
||||
assert x.py__name__() == expected_name
|
||||
@@ -163,9 +163,9 @@ def test_parent_context(same_process_evaluator, attribute, expected_name, expect
|
||||
(Counter("").most_common, ['Counter', 'most_common']),
|
||||
]
|
||||
)
|
||||
def test_qualified_names(same_process_evaluator, obj, expected_names):
|
||||
def test_qualified_names(same_process_infer_state, obj, expected_names):
|
||||
o = compiled.CompiledObject(
|
||||
same_process_evaluator,
|
||||
DirectObjectAccess(same_process_evaluator, obj)
|
||||
same_process_infer_state,
|
||||
DirectObjectAccess(same_process_infer_state, obj)
|
||||
)
|
||||
assert o.get_qualified_names() == tuple(expected_names)
|
||||
|
||||
@@ -66,7 +66,7 @@ def test_instance_doc(Script):
|
||||
assert defs[0].docstring() == 'Docstring of `TestClass`.'
|
||||
|
||||
|
||||
@unittest.skip('need evaluator class for that')
|
||||
@unittest.skip('need infer_state class for that')
|
||||
def test_attribute_docstring(Script):
|
||||
defs = Script("""
|
||||
x = None
|
||||
@@ -75,7 +75,7 @@ def test_attribute_docstring(Script):
|
||||
assert defs[0].docstring() == 'Docstring of `x`.'
|
||||
|
||||
|
||||
@unittest.skip('need evaluator class for that')
|
||||
@unittest.skip('need infer_state class for that')
|
||||
def test_multiple_docstrings(Script):
|
||||
defs = Script("""
|
||||
def func():
|
||||
|
||||
@@ -43,12 +43,12 @@ pkg_zip_path = os.path.join(os.path.dirname(__file__),
|
||||
'pkg.zip')
|
||||
|
||||
|
||||
def test_find_module_package_zipped(Script, evaluator, environment):
|
||||
def test_find_module_package_zipped(Script, infer_state, environment):
|
||||
sys_path = environment.get_sys_path() + [pkg_zip_path]
|
||||
script = Script('import pkg; pkg.mod', sys_path=sys_path)
|
||||
assert len(script.completions()) == 1
|
||||
|
||||
file_io, is_package = evaluator.compiled_subprocess.get_module_info(
|
||||
file_io, is_package = infer_state.compiled_subprocess.get_module_info(
|
||||
sys_path=sys_path,
|
||||
string=u'pkg',
|
||||
full_name=u'pkg'
|
||||
@@ -84,7 +84,7 @@ def test_find_module_package_zipped(Script, evaluator, environment):
|
||||
]
|
||||
|
||||
)
|
||||
def test_correct_zip_package_behavior(Script, evaluator, environment, code,
|
||||
def test_correct_zip_package_behavior(Script, infer_state, environment, code,
|
||||
file, package, path, skip_python2):
|
||||
sys_path = environment.get_sys_path() + [pkg_zip_path]
|
||||
pkg, = Script(code, sys_path=sys_path).goto_definitions()
|
||||
@@ -96,13 +96,13 @@ def test_correct_zip_package_behavior(Script, evaluator, environment, code,
|
||||
assert context.py__path__() == [os.path.join(pkg_zip_path, path)]
|
||||
|
||||
|
||||
def test_find_module_not_package_zipped(Script, evaluator, environment):
|
||||
def test_find_module_not_package_zipped(Script, infer_state, environment):
|
||||
path = os.path.join(os.path.dirname(__file__), 'zipped_imports/not_pkg.zip')
|
||||
sys_path = environment.get_sys_path() + [path]
|
||||
script = Script('import not_pkg; not_pkg.val', sys_path=sys_path)
|
||||
assert len(script.completions()) == 1
|
||||
|
||||
file_io, is_package = evaluator.compiled_subprocess.get_module_info(
|
||||
file_io, is_package = infer_state.compiled_subprocess.get_module_info(
|
||||
sys_path=sys_path,
|
||||
string=u'not_pkg',
|
||||
full_name=u'not_pkg'
|
||||
@@ -310,16 +310,16 @@ def test_compiled_import_none(monkeypatch, Script):
|
||||
(os.path.join(THIS_DIR, '__init__.py'), True, ('ok', 'lala', 'x', 'test_imports')),
|
||||
]
|
||||
)
|
||||
def test_get_modules_containing_name(evaluator, path, goal, is_package):
|
||||
def test_get_modules_containing_name(infer_state, path, goal, is_package):
|
||||
module = imports._load_python_module(
|
||||
evaluator,
|
||||
infer_state,
|
||||
FileIO(path),
|
||||
import_names=('ok', 'lala', 'x'),
|
||||
is_package=is_package,
|
||||
)
|
||||
assert module
|
||||
input_module, found_module = imports.get_modules_containing_name(
|
||||
evaluator,
|
||||
infer_state,
|
||||
[module],
|
||||
'string_that_only_exists_here'
|
||||
)
|
||||
@@ -337,9 +337,9 @@ def test_get_modules_containing_name(evaluator, path, goal, is_package):
|
||||
('/foo/bar/__init__.py', ('foo', 'bar'), True, ('foo', 'bar')),
|
||||
]
|
||||
)
|
||||
def test_load_module_from_path(evaluator, path, base_names, is_package, names):
|
||||
def test_load_module_from_path(infer_state, path, base_names, is_package, names):
|
||||
file_io = KnownContentFileIO(path, '')
|
||||
m = imports._load_module_from_path(evaluator, file_io, base_names)
|
||||
m = imports._load_module_from_path(infer_state, file_io, base_names)
|
||||
assert m.is_package == is_package
|
||||
assert m.string_names == names
|
||||
|
||||
@@ -437,8 +437,8 @@ def test_pre_defined_imports_module(Script, environment, name):
|
||||
module = Script('', path=path)._get_module()
|
||||
assert module.string_names == (name,)
|
||||
|
||||
assert module.evaluator.builtins_module.py__file__() != path
|
||||
assert module.evaluator.typing_module.py__file__() != path
|
||||
assert module.infer_state.builtins_module.py__file__() != path
|
||||
assert module.infer_state.typing_module.py__file__() != path
|
||||
|
||||
|
||||
@pytest.mark.parametrize('name', ('builtins', 'typing'))
|
||||
@@ -454,8 +454,8 @@ def test_import_needed_modules_by_jedi(Script, environment, tmpdir, name):
|
||||
sys_path=[tmpdir.strpath] + environment.get_sys_path(),
|
||||
)
|
||||
module, = script.goto_definitions()
|
||||
assert module._evaluator.builtins_module.py__file__() != module_path
|
||||
assert module._evaluator.typing_module.py__file__() != module_path
|
||||
assert module._infer_state.builtins_module.py__file__() != module_path
|
||||
assert module._infer_state.typing_module.py__file__() != module_path
|
||||
|
||||
|
||||
def test_import_with_semicolon(Script):
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
from textwrap import dedent
|
||||
|
||||
|
||||
def get_definition_and_evaluator(Script, source):
|
||||
def get_definition_and_infer_state(Script, source):
|
||||
first, = Script(dedent(source)).goto_definitions()
|
||||
return first._name._context, first._evaluator
|
||||
return first._name._context, first._infer_state
|
||||
|
||||
|
||||
def test_function_execution(Script):
|
||||
@@ -16,7 +16,7 @@ def test_function_execution(Script):
|
||||
def x():
|
||||
return str()
|
||||
x"""
|
||||
func, evaluator = get_definition_and_evaluator(Script, s)
|
||||
func, infer_state = get_definition_and_infer_state(Script, s)
|
||||
# Now just use the internals of the result (easiest way to get a fully
|
||||
# usable function).
|
||||
# Should return the same result both times.
|
||||
@@ -29,6 +29,6 @@ def test_class_mro(Script):
|
||||
class X(object):
|
||||
pass
|
||||
X"""
|
||||
cls, evaluator = get_definition_and_evaluator(Script, s)
|
||||
cls, infer_state = get_definition_and_infer_state(Script, s)
|
||||
mro = cls.py__mro__()
|
||||
assert [c.name.string_name for c in mro] == ['X', 'object']
|
||||
|
||||
Reference in New Issue
Block a user