1
0
forked from VimPlug/jedi

Infer doctests and signatures uniformly, fixes #1466

This commit is contained in:
Dave Halter
2020-01-03 00:45:14 +01:00
parent 2d31e2e760
commit 3b6bbab556
10 changed files with 89 additions and 20 deletions

View File

@@ -1,2 +1,6 @@
from . import module
func_with_stub = module.func_with_stub
both: int
stub_only: str

View File

@@ -1 +1,5 @@
in_sub_module: int
def func_with_stub(b: int) -> float:
pass

View File

@@ -1,2 +1,7 @@
from with_python import module as _module
func_without_stub = _module.func_without_stub
python_only = 1
both = ''

View File

@@ -1 +1,9 @@
def func_without_stub(a):
'nostubdoc'
def func_with_stub(c):
'withstubdoc'
in_sub_module = ''

View File

@@ -59,7 +59,7 @@ def test_help_no_returns(Script, code, kwargs):
('X.x', 'Yeah '),
('X().x', 'Yeah '),
('X.y', 'f g '),
('X.z', ''),
('X.z', '<lambda>(x)'),
]
)
def test_attribute_docstrings(goto_or_help, expected_doc, to_execute):
@@ -70,7 +70,7 @@ def test_attribute_docstrings(goto_or_help, expected_doc, to_execute):
""" Yeah """
y = 5
"f g "
z = lambda: 1
z = lambda x: 1
''')
d, = goto_or_help(code + to_execute)

View File

@@ -76,7 +76,7 @@ def test_multiple_docstrings(Script):
x = func
'''Docstring of `x`.'''
x""").help()
assert d.docstring() == 'Docstring of `x`.'
assert d.docstring() == 'func()\n\nDocstring of `x`.'
def test_completion(Script):
@@ -168,15 +168,13 @@ def test_import_function_docstring(Script, skip_pre_python35):
path = os.path.join(test_dir, 'completion', 'import_function_docstring.py')
c, = Script(code, path=path).complete()
stub_signature = 'stub_function(x: int, y: float) -> str'
python_signature = 'stub_function(x: float, y)'
doc = '\n\nPython docstring'
assert c.docstring() == stub_signature + doc
doc = 'stub_function(x: int, y: float) -> str\n\nPython docstring'
assert c.docstring() == doc
assert c.type == 'function'
func, = c.goto(prefer_stubs=True)
assert func.docstring() == stub_signature + doc
assert func.docstring() == doc
func, = c.goto()
assert func.docstring() == python_signature + doc
assert func.docstring() == doc
# ---- Numpy Style Tests ---

View File

@@ -25,3 +25,41 @@ def ScriptInStubFolder(Script):
def test_find_stubs_infer(ScriptInStubFolder, code, expected):
defs = ScriptInStubFolder(code).infer()
assert [d.name for d in defs] == expected
func_without_stub_sig = 'func_without_stub(a)'
func_without_stub_doc = func_without_stub_sig + '\n\nnostubdoc'
func_with_stub_doc = 'func_with_stub(b: int) -> float\n\nwithstubdoc'
@pytest.mark.parametrize(
('code', 'expected'), [
('from with_python import stub_only', ''),
('from with_python import python_only', ''),
('from with_python import both', ''),
('import with_python; with_python.func_without_stub', func_without_stub_sig),
('import with_python.module; with_python.module.func_without_stub', func_without_stub_doc),
('from with_python import module; module.func_without_stub', func_without_stub_doc),
('from with_python.module import func_without_stub', func_without_stub_doc),
('from with_python.module import func_without_stub as f; f', func_without_stub_doc),
('from with_python.module import func_without_stub; func_without_stub',
func_without_stub_doc),
('from with_python import func_without_stub', func_without_stub_sig),
('from with_python import func_without_stub as f; f', func_without_stub_sig),
('from with_python import func_without_stub; func_without_stub', func_without_stub_sig),
('import with_python; with_python.func_with_stub', func_with_stub_doc),
('import with_python.module; with_python.module.func_with_stub', func_with_stub_doc),
('from with_python import module; module.func_with_stub', func_with_stub_doc),
('from with_python.module import func_with_stub', func_with_stub_doc),
('from with_python.module import func_with_stub as f; f', func_with_stub_doc),
('from with_python.module import func_with_stub; func_with_stub', func_with_stub_doc),
('from with_python import func_with_stub', func_with_stub_doc),
('from with_python import func_with_stub as f; f', func_with_stub_doc),
('from with_python import func_with_stub; func_with_stub', func_with_stub_doc),
]
)
def test_docstrings(ScriptInStubFolder, code, expected):
d, = ScriptInStubFolder(code).help()
assert d.docstring() == expected