mirror of
https://github.com/davidhalter/jedi.git
synced 2026-01-30 11:05:21 +08:00
Merge pull request #176 from tkf/basedefinition-type
More detailed BaseDefinition.type (fixes #169)
This commit is contained in:
53
test/test_api_classes.py
Normal file
53
test/test_api_classes.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import textwrap
|
||||
|
||||
import pytest
|
||||
|
||||
from jedi import api
|
||||
|
||||
|
||||
def make_definitions():
|
||||
"""
|
||||
Return a list of definitions for parametrized tests.
|
||||
|
||||
:rtype: [jedi.api_classes.BaseDefinition]
|
||||
"""
|
||||
source = textwrap.dedent("""
|
||||
import sys
|
||||
|
||||
class C:
|
||||
pass
|
||||
|
||||
x = C()
|
||||
|
||||
def f():
|
||||
pass
|
||||
|
||||
def g():
|
||||
yield
|
||||
|
||||
h = lambda: None
|
||||
""")
|
||||
|
||||
definitions = []
|
||||
definitions += api.defined_names(source)
|
||||
|
||||
source += textwrap.dedent("""
|
||||
variable = sys or C or x or f or g or h""")
|
||||
lines = source.splitlines()
|
||||
script = api.Script(source, len(lines), len('variable'), None)
|
||||
definitions += script.definition()
|
||||
|
||||
script2 = api.Script(source, 4, len('class C'), None)
|
||||
definitions += script2.related_names()
|
||||
|
||||
source_param = "def f(a): return a"
|
||||
script_param = api.Script(source_param, 1, len(source_param), None)
|
||||
definitions += script_param.goto()
|
||||
|
||||
return definitions
|
||||
|
||||
|
||||
@pytest.mark.parametrize('definition', make_definitions())
|
||||
def test_basedefinition_type(definition):
|
||||
assert definition.type in ('module', 'class', 'instance', 'function',
|
||||
'statement', 'import', 'param')
|
||||
@@ -319,7 +319,7 @@ class TestRegression(TestBase):
|
||||
# attributes
|
||||
objs = itertools.chain.from_iterable(r.follow_definition() for r in c)
|
||||
types = [o.type for o in objs]
|
||||
assert 'Import' not in types and 'Class' in types
|
||||
assert 'import' not in types and 'class' in types
|
||||
|
||||
def test_keyword_definition_doc(self):
|
||||
""" github jedi-vim issue #44 """
|
||||
|
||||
Reference in New Issue
Block a user