mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
Fix some tests
This commit is contained in:
@@ -15,6 +15,7 @@ from jedi.evaluate import compiled
|
|||||||
from jedi.evaluate.imports import ImportName
|
from jedi.evaluate.imports import ImportName
|
||||||
from jedi.evaluate.context import instance
|
from jedi.evaluate.context import instance
|
||||||
from jedi.evaluate.context import ClassContext, FunctionExecutionContext
|
from jedi.evaluate.context import ClassContext, FunctionExecutionContext
|
||||||
|
from jedi.plugins.typeshed import StubOnlyModuleContext
|
||||||
from jedi.api.keywords import KeywordName
|
from jedi.api.keywords import KeywordName
|
||||||
|
|
||||||
|
|
||||||
@@ -203,6 +204,10 @@ class BaseDefinition(object):
|
|||||||
|
|
||||||
def in_builtin_module(self):
|
def in_builtin_module(self):
|
||||||
"""Whether this is a builtin module."""
|
"""Whether this is a builtin module."""
|
||||||
|
print(self._module)
|
||||||
|
if isinstance(self._module, StubOnlyModuleContext):
|
||||||
|
return any(isinstance(context, compiled.CompiledObject)
|
||||||
|
for context in self._module.non_stub_context_set)
|
||||||
return isinstance(self._module, compiled.CompiledObject)
|
return isinstance(self._module, compiled.CompiledObject)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -255,7 +255,6 @@ class TypeAlias(object):
|
|||||||
# There should only be one, because it's code that we control.
|
# There should only be one, because it's code that we control.
|
||||||
assert len(classes) == 1, classes
|
assert len(classes) == 1, classes
|
||||||
cls = next(iter(classes))
|
cls = next(iter(classes))
|
||||||
assert isinstance(cls, ClassContext), cls
|
|
||||||
return cls
|
return cls
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -357,10 +357,10 @@ class StubFunctionContext(_MixedStubContextMixin, FunctionContext):
|
|||||||
class StubOnlyModuleContext(ModuleContext):
|
class StubOnlyModuleContext(ModuleContext):
|
||||||
def __init__(self, non_stub_context_set, *args, **kwargs):
|
def __init__(self, non_stub_context_set, *args, **kwargs):
|
||||||
super(StubOnlyModuleContext, self).__init__(*args, **kwargs)
|
super(StubOnlyModuleContext, self).__init__(*args, **kwargs)
|
||||||
self._non_stub_context_set = non_stub_context_set
|
self.non_stub_context_set = non_stub_context_set
|
||||||
|
|
||||||
def _get_first_non_stub_filters(self):
|
def _get_first_non_stub_filters(self):
|
||||||
for context in self._non_stub_context_set:
|
for context in self.non_stub_context_set:
|
||||||
yield next(context.get_filters(search_global=False))
|
yield next(context.get_filters(search_global=False))
|
||||||
|
|
||||||
def get_filters(self, search_global, until_position=None,
|
def get_filters(self, search_global, until_position=None,
|
||||||
|
|||||||
@@ -5,17 +5,24 @@ Test all things related to the ``jedi.api`` module.
|
|||||||
import os
|
import os
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
from jedi import preload_module
|
|
||||||
from jedi._compatibility import is_py3
|
|
||||||
from pytest import raises
|
from pytest import raises
|
||||||
from parso import cache
|
from parso import cache
|
||||||
|
|
||||||
|
from jedi import preload_module
|
||||||
|
from jedi._compatibility import is_py3
|
||||||
|
from jedi.plugins import typeshed
|
||||||
|
|
||||||
|
|
||||||
def test_preload_modules():
|
def test_preload_modules():
|
||||||
def check_loaded(*modules):
|
def check_loaded(*modules):
|
||||||
# +1 for None module (currently used)
|
# +1 for None module (currently used)
|
||||||
grammar_cache = next(iter(cache.parser_cache.values()))
|
grammar_cache = next(iter(cache.parser_cache.values()))
|
||||||
assert len(grammar_cache) == len(modules) + 1
|
# Filter the typeshed parser cache.
|
||||||
|
typeshed_cache_count = sum(
|
||||||
|
1 for path in grammar_cache
|
||||||
|
if path is not None and path.startswith(typeshed._TYPESHED_PATH)
|
||||||
|
)
|
||||||
|
assert len(grammar_cache) - typeshed_cache_count == len(modules) + 1
|
||||||
for i in modules:
|
for i in modules:
|
||||||
assert [i in k for k in grammar_cache.keys() if k is not None]
|
assert [i in k for k in grammar_cache.keys() if k is not None]
|
||||||
|
|
||||||
@@ -292,4 +299,4 @@ def test_goto_follow_builtin_imports(Script):
|
|||||||
d, = s.goto_assignments(follow_imports=True)
|
d, = s.goto_assignments(follow_imports=True)
|
||||||
assert d.in_builtin_module() is True
|
assert d.in_builtin_module() is True
|
||||||
d, = s.goto_assignments(follow_imports=True, follow_builtin_imports=True)
|
d, = s.goto_assignments(follow_imports=True, follow_builtin_imports=True)
|
||||||
assert d.in_builtin_module() is False
|
assert d.in_builtin_module() is True
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import pytest
|
|||||||
|
|
||||||
from ..helpers import TestCase
|
from ..helpers import TestCase
|
||||||
from jedi import cache
|
from jedi import cache
|
||||||
|
from jedi.parser_utils import get_call_signature
|
||||||
from jedi._compatibility import is_py3
|
from jedi._compatibility import is_py3
|
||||||
|
|
||||||
|
|
||||||
@@ -229,7 +230,15 @@ def test_complex(Script):
|
|||||||
re.compile(
|
re.compile(
|
||||||
return it * 2
|
return it * 2
|
||||||
"""
|
"""
|
||||||
assert_signature(Script, s, 'compile', 0, line=4, column=27)
|
sig1, sig2 = sorted(Script(s, line=4, column=27).call_signatures(), key=lambda s: s.line)
|
||||||
|
assert sig1.name == sig2.name == 'compile'
|
||||||
|
assert sig1.index == sig2.index == 0
|
||||||
|
func1, = sig1._name.infer()
|
||||||
|
func2, = sig2._name.infer()
|
||||||
|
assert get_call_signature(func1.tree_node) \
|
||||||
|
== 'compile(pattern: AnyStr, flags: _FlagsType = ...) -> Pattern[AnyStr]'
|
||||||
|
assert get_call_signature(func2.tree_node) \
|
||||||
|
== 'compile(pattern: Pattern[AnyStr], flags: _FlagsType = ...) ->\nPattern[AnyStr]'
|
||||||
|
|
||||||
# jedi-vim #70
|
# jedi-vim #70
|
||||||
s = """def foo("""
|
s = """def foo("""
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ def test_exclude_builtin_modules(Script):
|
|||||||
return [(d.line, d.column) for d in Script(source, column=8).usages(include_builtins=include)]
|
return [(d.line, d.column) for d in Script(source, column=8).usages(include_builtins=include)]
|
||||||
source = '''import sys\nprint(sys.path)'''
|
source = '''import sys\nprint(sys.path)'''
|
||||||
places = get(include=True)
|
places = get(include=True)
|
||||||
assert places == [(None, None), (1, 7), (2, 6)]
|
assert places == [(1, 7), (2, 6)]
|
||||||
|
|
||||||
places = get(include=False)
|
places = get(include=False)
|
||||||
assert places == [(1, 7), (2, 6)]
|
assert places == [(1, 7), (2, 6)]
|
||||||
|
|||||||
Reference in New Issue
Block a user