import _ast

from peon.src.project.file.function_def.function import FunctionLint


class ReflectionAtLineFixture:
    empty_node = _ast.Pass
    is_instance_at_first_lvl = _ast.FunctionDef(id='isinstance', lineno=1)
    type_at_first_lvl = _ast.FunctionDef(id='type', lineno=1)
    is_instance_at_second_lvl = _ast.FunctionDef(body=[_ast.Expr(id='isinstance', lineno=2)], lineno=1)
    type_at_second_lvl = _ast.FunctionDef(body=[_ast.Expr(id='type', lineno=2)], lineno=1)


def test_empty_node():
    assert FunctionLint(
        definition=ReflectionAtLineFixture.empty_node,
    ).reflection_at_line() == tuple()


def test_is_instance_at_first_lvl():
    assert FunctionLint(
        definition=ReflectionAtLineFixture.is_instance_at_first_lvl,
    ).reflection_at_line() == (1,)


def test_type_at_first_lvl():
    assert FunctionLint(
        definition=ReflectionAtLineFixture.type_at_first_lvl,
    ).reflection_at_line() == (1,)


def test_is_instance_at_second_lvl():
    assert FunctionLint(
        definition=ReflectionAtLineFixture.is_instance_at_second_lvl,
    ).reflection_at_line() == (2,)


def test_type_at_second_lvl():
    assert FunctionLint(
        definition=ReflectionAtLineFixture.type_at_second_lvl,
    ).reflection_at_line() == (2,)

[(8, '_ast.FunctionDef', '_ast.FunctionDef', False, 'import _ast\n'), (9, '_ast.FunctionDef', '_ast.FunctionDef', False, 'import _ast\n'), (10, '_ast.Expr', '_ast.Expr', False, 'import _ast\n'), (11, '_ast.Expr', '_ast.Expr', False, 'import _ast\n'), (15, 'peon.src.project.file.function_def.function.FunctionLint', 'FunctionLint', False, 'from peon.src.project.file.function_def.function import FunctionLint\n'), (21, 'peon.src.project.file.function_def.function.FunctionLint', 'FunctionLint', False, 'from peon.src.project.file.function_def.function import FunctionLint\n'), (27, 'peon.src.project.file.function_def.function.FunctionLint', 'FunctionLint', False, 'from peon.src.project.file.function_def.function import FunctionLint\n'), (33, 'peon.src.project.file.function_def.function.FunctionLint', 'FunctionLint', False, 'from peon.src.project.file.function_def.function import FunctionLint\n'), (39, 'peon.src.project.file.function_def.function.FunctionLint', 'FunctionLint', False, 'from peon.src.project.file.function_def.function import FunctionLint\n')]