Merge pull request #176 from tkf/basedefinition-type

More detailed BaseDefinition.type (fixes #169)
This commit is contained in:
David Halter
2013-03-15 10:36:53 -07:00
4 changed files with 70 additions and 9 deletions

53
test/test_api_classes.py Normal file
View 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')

View File

@@ -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 """