mirror of
https://github.com/davidhalter/jedi.git
synced 2026-01-30 20:35:23 +08:00
Merge branch 'master' into relative-import
This commit is contained in:
@@ -179,3 +179,22 @@ def argskwargs(*args: int, **kwargs: float):
|
||||
next(iter(kwargs.keys()))
|
||||
#? float()
|
||||
kwargs['']
|
||||
|
||||
|
||||
class NotCalledClass:
|
||||
def __init__(self, x):
|
||||
self.x: int = x
|
||||
self.y: int = ''
|
||||
#? int()
|
||||
self.x
|
||||
#? int()
|
||||
self.y
|
||||
#? int()
|
||||
self.y
|
||||
self.z: int
|
||||
self.z = ''
|
||||
#? str() int()
|
||||
self.z
|
||||
self.w: float
|
||||
#? float()
|
||||
self.w
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
from .cq import selectors
|
||||
1
test/examples/import-recursion/cadquery_simple/cq.py
Normal file
1
test/examples/import-recursion/cadquery_simple/cq.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import selectors
|
||||
3
test/examples/import-recursion/cq_example.py
Normal file
3
test/examples/import-recursion/cq_example.py
Normal file
@@ -0,0 +1,3 @@
|
||||
import cadquery_simple as cq
|
||||
|
||||
cq.
|
||||
@@ -370,3 +370,35 @@ def test_multi_goto(Script):
|
||||
y, = script.goto(line=4)
|
||||
assert x.line == 1
|
||||
assert y.line == 2
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'code, column, expected', [
|
||||
('str() ', 3, 'str'),
|
||||
('str() ', 4, 'str'),
|
||||
('str() ', 5, 'str'),
|
||||
('str() ', 6, None),
|
||||
('str( ) ', 6, None),
|
||||
(' 1', 1, None),
|
||||
('str(1) ', 3, 'str'),
|
||||
('str(1) ', 4, 'int'),
|
||||
('str(1) ', 5, 'int'),
|
||||
('str(1) ', 6, 'str'),
|
||||
('str(1) ', 7, None),
|
||||
('str( 1) ', 4, 'str'),
|
||||
('str( 1) ', 5, 'int'),
|
||||
('str(+1) ', 4, 'str'),
|
||||
('str(+1) ', 5, 'int'),
|
||||
('str(1, 1.) ', 3, 'str'),
|
||||
('str(1, 1.) ', 4, 'int'),
|
||||
('str(1, 1.) ', 5, 'int'),
|
||||
('str(1, 1.) ', 6, None),
|
||||
('str(1, 1.) ', 7, 'float'),
|
||||
]
|
||||
)
|
||||
def test_infer_after_parentheses(Script, code, column, expected):
|
||||
completions = Script(code).infer(column=column)
|
||||
if expected is None:
|
||||
assert completions == []
|
||||
else:
|
||||
assert [c.name for c in completions] == [expected]
|
||||
|
||||
@@ -513,10 +513,14 @@ def test_added_equals_to_params(Script):
|
||||
|
||||
assert run('foo(bar').name_with_symbols == 'bar='
|
||||
assert run('foo(bar').complete == '='
|
||||
assert run('foo(bar').get_completion_prefix_length() == 3
|
||||
assert run('foo(bar, baz').complete == '='
|
||||
assert run('foo(bar, baz').get_completion_prefix_length() == 3
|
||||
assert run(' bar').name_with_symbols == 'bar'
|
||||
assert run(' bar').complete == ''
|
||||
assert run(' bar').get_completion_prefix_length() == 3
|
||||
x = run('foo(bar=isins').name_with_symbols
|
||||
assert run('foo(bar=isins').get_completion_prefix_length() == 5
|
||||
assert x == 'isinstance'
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import pytest
|
||||
from ..helpers import get_example_dir, set_cwd, root_dir, test_dir
|
||||
from jedi import Interpreter
|
||||
from jedi.api import Project, get_default_project
|
||||
from jedi.api.project import _is_potential_project, _CONTAINS_POTENTIAL_PROJECT
|
||||
|
||||
|
||||
def test_django_default_project(Script):
|
||||
@@ -160,3 +161,21 @@ def test_complete_search(Script, string, completions, all_scopes):
|
||||
project = Project(test_dir)
|
||||
defs = project.complete_search(string, all_scopes=all_scopes)
|
||||
assert [d.complete for d in defs] == completions
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'path,expected', [
|
||||
(Path(__file__).parents[2], True), # The path of the project
|
||||
(Path(__file__).parents[1], False), # The path of the tests, not a project
|
||||
(Path.home(), None)
|
||||
]
|
||||
)
|
||||
def test_is_potential_project(path, expected):
|
||||
|
||||
if expected is None:
|
||||
try:
|
||||
expected = _CONTAINS_POTENTIAL_PROJECT in os.listdir(path)
|
||||
except OSError:
|
||||
expected = False
|
||||
|
||||
assert _is_potential_project(path) == expected
|
||||
|
||||
@@ -206,6 +206,24 @@ def test_numpydoc_parameters_set_of_values():
|
||||
assert 'capitalize' in names
|
||||
assert 'numerator' in names
|
||||
|
||||
@pytest.mark.skipif(numpydoc_unavailable,
|
||||
reason='numpydoc module is unavailable')
|
||||
def test_numpydoc_parameters_set_single_value():
|
||||
"""
|
||||
This is found in numpy masked-array I'm not too sure what this means but should not crash
|
||||
"""
|
||||
s = dedent('''
|
||||
def foobar(x, y):
|
||||
"""
|
||||
Parameters
|
||||
----------
|
||||
x : {var}, optional
|
||||
"""
|
||||
x.''')
|
||||
names = [c.name for c in jedi.Script(s).complete()]
|
||||
# just don't crash
|
||||
assert names == []
|
||||
|
||||
|
||||
@pytest.mark.skipif(numpydoc_unavailable,
|
||||
reason='numpydoc module is unavailable')
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
from parso.cache import parser_cache
|
||||
|
||||
from test.helpers import root_dir
|
||||
from jedi.api.project import Project
|
||||
@@ -64,6 +65,17 @@ def test_goto_import(Script):
|
||||
assert not d.is_stub()
|
||||
|
||||
|
||||
def test_stub_get_line_code(Script):
|
||||
code = 'from abc import ABC; ABC'
|
||||
script = Script(code)
|
||||
d, = script.goto(only_stubs=True)
|
||||
assert d.get_line_code() == 'class ABC(metaclass=ABCMeta): ...\n'
|
||||
del parser_cache[script._inference_state.latest_grammar._hashed][d.module_path]
|
||||
d, = Script(path=d.module_path).goto(d.line, d.column, only_stubs=True)
|
||||
assert d.is_stub()
|
||||
assert d.get_line_code() == 'class ABC(metaclass=ABCMeta): ...\n'
|
||||
|
||||
|
||||
def test_os_stat_result(Script):
|
||||
d, = Script('import os; os.stat_result').goto()
|
||||
assert d.is_stub()
|
||||
|
||||
@@ -489,3 +489,9 @@ def test_relative_imports_without_path_and_setup_py(
|
||||
assert n.name == name
|
||||
assert n.type == 'module'
|
||||
assert n.line == 1
|
||||
|
||||
|
||||
def test_import_recursion(Script):
|
||||
path = get_example_dir('import-recursion', "cq_example.py")
|
||||
for c in Script(path=path).complete(3, 3):
|
||||
c.docstring()
|
||||
|
||||
@@ -340,3 +340,20 @@ def test_overload(Script, code):
|
||||
x1, x2 = Script(code, path=os.path.join(dir_, 'foo.py')).get_signatures()
|
||||
assert x1.to_string() == 'with_overload(x: int, y: int) -> float'
|
||||
assert x2.to_string() == 'with_overload(x: str, y: list) -> float'
|
||||
|
||||
|
||||
def test_enum(Script):
|
||||
script = Script('''\
|
||||
from enum import Enum
|
||||
|
||||
class Planet(Enum):
|
||||
MERCURY = (3.303e+23, 2.4397e6)
|
||||
VENUS = (4.869e+24, 6.0518e6)
|
||||
|
||||
def __init__(self, mass, radius):
|
||||
self.mass = mass # in kilograms
|
||||
self.radius = radius # in meters
|
||||
|
||||
Planet.MERCURY''')
|
||||
completion, = script.complete()
|
||||
assert not completion.get_signatures()
|
||||
|
||||
Reference in New Issue
Block a user