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, 31, 8, 74), '_ast.FunctionDef', '_ast.FunctionDef', (), '', False, 'import _ast\n'), ((9, 24, 9, 61), '_ast.FunctionDef', '_ast.FunctionDef', (), '', False, 'import _ast\n'), ((10, 55, 10, 91), '_ast.Expr', '_ast.Expr', (), '', False, 'import _ast\n'), ((11, 48, 11, 78), '_ast.Expr', '_ast.Expr', (), '', False, 'import _ast\n'), ((15, 11, 17, 5), 'peon.src.project.file.function_def.function.FunctionLint', 'FunctionLint', (), '', False, 'from peon.src.project.file.function_def.function import FunctionLint\n'), ((21, 11, 23, 5), 'peon.src.project.file.function_def.function.FunctionLint', 'FunctionLint', (), '', False, 'from peon.src.project.file.function_def.function import FunctionLint\n'), ((27, 11, 29, 5), 'peon.src.project.file.function_def.function.FunctionLint', 'FunctionLint', (), '', False, 'from peon.src.project.file.function_def.function import FunctionLint\n'), ((33, 11, 35, 5), 'peon.src.project.file.function_def.function.FunctionLint', 'FunctionLint', (), '', False, 'from peon.src.project.file.function_def.function import FunctionLint\n'), ((39, 11, 41, 5), 'peon.src.project.file.function_def.function.FunctionLint', 'FunctionLint', (), '', False, 'from peon.src.project.file.function_def.function import FunctionLint\n')]