Some test fixes

This commit is contained in:
Dave Halter
2019-03-28 19:23:55 +01:00
parent aa37f6f738
commit 2f1ce2bbf9
4 changed files with 11 additions and 7 deletions

View File

@@ -127,7 +127,7 @@ def _from_loader(loader, string):
# To avoid unicode and read bytes, "overwrite" loader.get_source if # To avoid unicode and read bytes, "overwrite" loader.get_source if
# possible. # possible.
f = loader.get_source.__func__ f = type(loader).get_source
if is_py3 and f is not importlib.machinery.SourceFileLoader.get_source: if is_py3 and f is not importlib.machinery.SourceFileLoader.get_source:
# Unfortunately we are reading unicode here, not bytes. # Unfortunately we are reading unicode here, not bytes.
# It seems hard to get bytes, because the zip importer # It seems hard to get bytes, because the zip importer

View File

@@ -128,17 +128,18 @@ class Environment(_BaseEnvironment):
return self._get_subprocess().get_sys_path() return self._get_subprocess().get_sys_path()
class SameEnvironment(Environment): class _SameEnvironmentMixin(object):
def __init__(self): def __init__(self):
self._start_executable = self.executable = sys.executable self._start_executable = self.executable = sys.executable
self.path = sys.prefix self.path = sys.prefix
self.version_info = _VersionInfo(*sys.version_info[:3]) self.version_info = _VersionInfo(*sys.version_info[:3])
class InterpreterEnvironment(_BaseEnvironment): class SameEnvironment(_SameEnvironmentMixin, Environment):
def __init__(self): pass
self.version_info = _VersionInfo(*sys.version_info[:3])
class InterpreterEnvironment(_SameEnvironmentMixin, _BaseEnvironment):
def get_evaluator_subprocess(self, evaluator): def get_evaluator_subprocess(self, evaluator):
return EvaluatorSameProcess(evaluator) return EvaluatorSameProcess(evaluator)

View File

@@ -210,7 +210,7 @@ def transform_path_to_dotted(sys_path, module_path):
Returns the dotted path inside a sys.path as a list of names. e.g. Returns the dotted path inside a sys.path as a list of names. e.g.
>>> transform_path_to_dotted(["/foo"], '/foo/bar/baz.py') >>> transform_path_to_dotted(["/foo"], '/foo/bar/baz.py')
('bar', 'baz'), False (('bar', 'baz'), False)
Returns (None, False) if the path doesn't really resolve to anything. Returns (None, False) if the path doesn't really resolve to anything.
The second return part is if it is a package. The second return part is if it is a package.

View File

@@ -55,7 +55,10 @@ def test_load_module(evaluator):
access_handle.py__mro__() access_handle.py__mro__()
def test_error_in_environment(evaluator, Script): def test_error_in_environment(evaluator, 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. # Provoke an error to show how Jedi can recover from it.
with pytest.raises(jedi.InternalError): with pytest.raises(jedi.InternalError):
evaluator.compiled_subprocess._test_raise_error(KeyboardInterrupt) evaluator.compiled_subprocess._test_raise_error(KeyboardInterrupt)