From 2f1ce2bbf97419434b12db0c4786f1a28d74b5cc Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 28 Mar 2019 19:23:55 +0100 Subject: [PATCH] Some test fixes --- jedi/_compatibility.py | 2 +- jedi/api/environment.py | 9 +++++---- jedi/evaluate/sys_path.py | 2 +- test/test_api/test_environment.py | 5 ++++- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/jedi/_compatibility.py b/jedi/_compatibility.py index 8f7bc01f..54c19df7 100644 --- a/jedi/_compatibility.py +++ b/jedi/_compatibility.py @@ -127,7 +127,7 @@ def _from_loader(loader, string): # To avoid unicode and read bytes, "overwrite" loader.get_source if # possible. - f = loader.get_source.__func__ + f = type(loader).get_source if is_py3 and f is not importlib.machinery.SourceFileLoader.get_source: # Unfortunately we are reading unicode here, not bytes. # It seems hard to get bytes, because the zip importer diff --git a/jedi/api/environment.py b/jedi/api/environment.py index 0d2b6729..ee014858 100644 --- a/jedi/api/environment.py +++ b/jedi/api/environment.py @@ -128,17 +128,18 @@ class Environment(_BaseEnvironment): return self._get_subprocess().get_sys_path() -class SameEnvironment(Environment): +class _SameEnvironmentMixin(object): def __init__(self): self._start_executable = self.executable = sys.executable self.path = sys.prefix self.version_info = _VersionInfo(*sys.version_info[:3]) -class InterpreterEnvironment(_BaseEnvironment): - def __init__(self): - self.version_info = _VersionInfo(*sys.version_info[:3]) +class SameEnvironment(_SameEnvironmentMixin, Environment): + pass + +class InterpreterEnvironment(_SameEnvironmentMixin, _BaseEnvironment): def get_evaluator_subprocess(self, evaluator): return EvaluatorSameProcess(evaluator) diff --git a/jedi/evaluate/sys_path.py b/jedi/evaluate/sys_path.py index ae5c4dac..4a6fd6ca 100644 --- a/jedi/evaluate/sys_path.py +++ b/jedi/evaluate/sys_path.py @@ -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. >>> 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. The second return part is if it is a package. diff --git a/test/test_api/test_environment.py b/test/test_api/test_environment.py index 5c1911e4..40f48d36 100644 --- a/test/test_api/test_environment.py +++ b/test/test_api/test_environment.py @@ -55,7 +55,10 @@ def test_load_module(evaluator): 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. with pytest.raises(jedi.InternalError): evaluator.compiled_subprocess._test_raise_error(KeyboardInterrupt)