<commit_before>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')<commit_msg>AttributeError: 'Generator' object has no attribute 'start_pos'<commit_after>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')
{'fraction_non_alphanumeric': 0.1284961491690312, 'fraction_numerical': 0.0032428050263477908, 'mean_word_length': 2.9236883942766294, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4706070', 'n_tokens_mistral': 754, 'n_tokens_neox': 735, 'n_words': 207}