mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 15:24:46 +08:00
Simplify some test code for param defaults, see #1356
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
import inspect
|
import inspect
|
||||||
import warnings
|
|
||||||
|
|
||||||
import pytest
|
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.parser_utils import get_call_signature
|
||||||
|
from jedi import Interpreter
|
||||||
|
|
||||||
|
|
||||||
def assert_signature(Script, source, expected_name, expected_index=0, line=None, column=None):
|
def assert_signature(Script, source, expected_name, expected_index=0, line=None, column=None):
|
||||||
@@ -394,9 +394,8 @@ def test_keyword_argument_index(Script, environment):
|
|||||||
assert get(both + 'foo(a, b, c').index == 0
|
assert get(both + 'foo(a, b, c').index == 0
|
||||||
|
|
||||||
|
|
||||||
def test_kwarg_defaults(Script, environment):
|
@pytest.mark.parametrize('code', ['foo', 'instance.foo'])
|
||||||
from jedi import Interpreter
|
def test_kwarg_defaults(Script, environment, code):
|
||||||
|
|
||||||
def foo(kwarg="bla", kwarg1=1):
|
def foo(kwarg="bla", kwarg1=1):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -404,47 +403,30 @@ def test_kwarg_defaults(Script, environment):
|
|||||||
def foo(self, kwarg="bla", kwarg1=1):
|
def foo(self, kwarg="bla", kwarg1=1):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
klass = Klass()
|
instance = Klass()
|
||||||
|
|
||||||
loc = dict()
|
src = dedent("""
|
||||||
loc['foo'] = foo
|
def foo2(kwarg="bla", kwarg1=1):
|
||||||
loc['klass'] = klass
|
|
||||||
|
|
||||||
signatures = Interpreter('foo(', namespaces=[loc]).call_signatures()
|
|
||||||
assert signatures[0].params[0].description == 'param kwarg="bla"'
|
|
||||||
assert signatures[0].params[1].description == 'param kwarg1=1'
|
|
||||||
|
|
||||||
signatures = Interpreter('klass.foo(', namespaces=[loc]).call_signatures()
|
|
||||||
assert signatures[0].params[0].description == 'param kwarg="bla"'
|
|
||||||
assert signatures[0].params[1].description == 'param kwarg1=1'
|
|
||||||
|
|
||||||
src = """
|
|
||||||
def foo(kwarg="bla", kwarg1=1):
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class Klass:
|
class Klass2:
|
||||||
def foo(self, kwarg="bla", kwarg1=1):
|
def foo2(self, kwarg="bla", kwarg1=1):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
klass = Klass()
|
instance = Klass2()
|
||||||
|
""")
|
||||||
|
|
||||||
"""
|
executed_locals = dict()
|
||||||
signatures = Script(src+"foo(").call_signatures()
|
exec(src, None, executed_locals)
|
||||||
assert signatures[0].params[0].description == 'param kwarg="bla"'
|
locals_ = locals()
|
||||||
assert signatures[0].params[1].description == 'param kwarg1=1'
|
|
||||||
|
|
||||||
signatures = Script(src+"klass.foo(").call_signatures()
|
def iter_scripts():
|
||||||
assert signatures[0].params[0].description == 'param kwarg="bla"'
|
yield Interpreter(code + '(', namespaces=[locals_])
|
||||||
assert signatures[0].params[1].description == 'param kwarg1=1'
|
yield Script(src + code + "2(")
|
||||||
|
yield Interpreter(code + '2(', namespaces=[executed_locals])
|
||||||
|
|
||||||
loc = dict()
|
for script in iter_scripts():
|
||||||
exec(src, None, loc)
|
signatures = script.call_signatures()
|
||||||
|
|
||||||
signatures = Interpreter('foo(', namespaces=[loc]).call_signatures()
|
|
||||||
assert signatures[0].params[0].description == 'param kwarg="bla"'
|
|
||||||
assert signatures[0].params[1].description == 'param kwarg1=1'
|
|
||||||
|
|
||||||
signatures = Interpreter('klass.foo(', namespaces=[loc]).call_signatures()
|
|
||||||
assert signatures[0].params[0].description == 'param kwarg="bla"'
|
assert signatures[0].params[0].description == 'param kwarg="bla"'
|
||||||
assert signatures[0].params[1].description == 'param kwarg1=1'
|
assert signatures[0].params[1].description == 'param kwarg1=1'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user