Fix some tests

This commit is contained in:
Dave Halter
2018-09-05 00:10:25 +02:00
parent e086c433ff
commit ab872b9a34
6 changed files with 29 additions and 9 deletions

View File

@@ -5,17 +5,24 @@ Test all things related to the ``jedi.api`` module.
import os
from textwrap import dedent
from jedi import preload_module
from jedi._compatibility import is_py3
from pytest import raises
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 check_loaded(*modules):
# +1 for None module (currently used)
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:
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)
assert d.in_builtin_module() is 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

View File

@@ -6,6 +6,7 @@ import pytest
from ..helpers import TestCase
from jedi import cache
from jedi.parser_utils import get_call_signature
from jedi._compatibility import is_py3
@@ -229,7 +230,15 @@ def test_complex(Script):
re.compile(
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
s = """def foo("""

View File

@@ -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)]
source = '''import sys\nprint(sys.path)'''
places = get(include=True)
assert places == [(None, None), (1, 7), (2, 6)]
assert places == [(1, 7), (2, 6)]
places = get(include=False)
assert places == [(1, 7), (2, 6)]