mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 06:24:27 +08:00
Running py.test raises this error:
```tb
test/test_api_classes.py:50: in <module>
> @pytest.mark.parametrize('definition', make_definitions())
test/test_api_classes.py:38: in make_definitions
> definitions += script.definition()
jedi/api_classes.py:44: in wrapper
> result = func(*args, **kwds)
jedi/api.py:274: in definition
> if not isinstance(s, imports.ImportPath._GlobalNamespace)])
jedi/api_classes.py:418: in __init__
> super(Definition, self).__init__(definition, definition.start_pos)
E AttributeError: 'Generator' object has no attribute 'start_pos'
```
54 lines
1.2 KiB
Python
54 lines
1.2 KiB
Python
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 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')
|