Make the new project API fully work in tests

This commit is contained in:
Dave Halter
2018-01-17 09:54:11 +01:00
parent fe813292cf
commit 9b5e3447d9
6 changed files with 20 additions and 14 deletions

View File

@@ -121,7 +121,7 @@ class Script(object):
project = get_default_project()
# TODO deprecate and remove sys_path from the Script API.
project._sys_path = sys_path
self._evaluator = Evaluator(project, environment)
self._evaluator = Evaluator(project, environment=environment, script_path=path)
self._project = project
debug.speed('init')

View File

@@ -87,12 +87,12 @@ class Project(object):
one is used like a public method.
"""
sys_path = list(self._get_base_sys_path(environment))
if self._smart_sys_path:
if evaluator.script_path is None or not self._smart_sys_path:
return sys_path
added_paths = map(
force_unicode,
detect_additional_paths(self._evaluator, self._script_path)
detect_additional_paths(evaluator, evaluator.script_path)
)
return sys_path + list(added_paths)

View File

@@ -67,7 +67,6 @@ import parso
from jedi import debug
from jedi import parser_utils
from jedi.api.environment import get_default_environment
from jedi.evaluate.utils import unite
from jedi.evaluate import imports
from jedi.evaluate import recursion
@@ -85,10 +84,11 @@ from jedi.evaluate.syntax_tree import eval_trailer, eval_expr_stmt, \
class Evaluator(object):
def __init__(self, project, environment=None):
def __init__(self, project, environment=None, script_path=None):
if environment is None:
environment = get_default_environment()
environment = project.get_environment()
self.environment = environment
self.script_path = script_path
self.compiled_subprocess = environment.get_evaluator_subprocess(self)
self.grammar = environment.get_grammar()

View File

@@ -13,6 +13,7 @@ import subprocess
import socket
import errno
import weakref
import traceback
from functools import partial
from jedi._compatibility import queue, is_py3, force_unicode, pickle_dump, pickle_load
@@ -195,12 +196,15 @@ class _CompiledSubprocess(object):
raise InternalError("The subprocess was killed. Maybe out of memory?")
try:
is_exception, result = pickle_load(self._process.stdout)
is_exception, traceback, result = pickle_load(self._process.stdout)
except EOFError:
self.kill()
raise InternalError("The subprocess crashed.")
if is_exception:
# Replace the attribute error message with a the traceback. It's
# way more informative.
result.args = (traceback,)
raise result
return result
@@ -270,11 +274,9 @@ class Listener(object):
# here and just exit.
exit(1)
try:
result = False, self._run(*payload)
result = False, None, self._run(*payload)
except Exception as e:
#import traceback
#print_to_stderr(traceback.format_exc())
result = True, e
result = True, traceback.format_exc(), e
pickle_dump(result, file=stdout)
stdout.flush()

View File

@@ -517,10 +517,11 @@ def get_modules_containing_name(evaluator, modules, name):
with open(path, 'rb') as f:
code = python_bytes_to_unicode(f.read(), errors='replace')
if name in code:
module = _load_module(evaluator, path, code)
e_sys_path = evaluator.get_sys_path()
module = _load_module(evaluator, path, code, sys_path=e_sys_path)
module_name = sys_path.dotted_path_in_sys_path(
evaluator.get_sys_path(), path
e_sys_path, path
)
if module_name is not None:
add_module(evaluator, module_name, module)

View File

@@ -43,7 +43,10 @@ def test_versions(version):
def test_load_module(evaluator):
access_path = evaluator.compiled_subprocess.load_module(name=u'math')
access_path = evaluator.compiled_subprocess.load_module(
name=u'math',
sys_path=evaluator.get_sys_path()
)
name, access_handle = access_path.accesses[0]
assert access_handle.py__bool__() is True