def test_outer_variable_double_shadow(
    assert_errors,
    parse_ast_tree,
    default_options,
    mode,
):
    """Testing that shadowing vars are not allowed."""
    tree = parse_ast_tree(
        mode("""
    a = 1

    def test1():
        a = 2

    def test2(a):
        ...
    """))

    visitor = BlockVariableVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [
        OuterScopeShadowingViolation,
        OuterScopeShadowingViolation,
    ])
def test_property_setter(
    assert_errors,
    parse_ast_tree,
    default_options,
    mode,
):
    """Ensures that property setter do not overlap."""
    code = method_setter_template.format('func')
    tree = parse_ast_tree(mode(code))

    visitor = BlockVariableVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [])
def test_block_unused_overlap(
    assert_errors,
    parse_ast_tree,
    default_options,
    code,
    mode,
):
    """Testing that overlaps between unused vars are ok."""
    tree = parse_ast_tree(mode(code))

    visitor = BlockVariableVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [])
def test_outer_variable_shadow(
    assert_errors,
    parse_ast_tree,
    default_options,
    code,
    mode,
):
    """Testing that shadowing vars are not allowed."""
    tree = parse_ast_tree(mode(code))

    visitor = BlockVariableVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [OuterScopeShadowingViolation])
def test_variable_used_correctly(
    assert_errors,
    parse_ast_tree,
    default_options,
    code,
    mode,
):
    """Testing that using variables inside a block is correct."""
    tree = parse_ast_tree(mode(code))

    visitor = BlockVariableVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [])
def test_no_function_overload(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    default_options,
    decorator_template,
    mode,
):
    """Ensures that not overload from typing do overlap."""
    code = overload_template.format(decorator_template, pipeline)
    tree = parse_ast_tree(mode(code))

    visitor = BlockVariableVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [BlockAndLocalOverlapViolation])
def test_function_overload(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    default_options,
    import_overload,
    mode,
):
    """Ensures that overload from typing do not overlap."""
    code = overload_template.format(import_overload, pipeline)
    tree = parse_ast_tree(mode(code))

    visitor = BlockVariableVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [])
def test_block_overlap(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    default_options,
    code,
    mode,
):
    """Testing that overlaps between blocks are forbiden."""
    tree = parse_ast_tree(mode(code))

    visitor = BlockVariableVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [BlockAndLocalOverlapViolation])
    assert_error_text(visitor, 'overlap')
Exemplo n.º 9
0
def test_except_block_regression1115(
    assert_errors,
    parse_ast_tree,
    code,
    violations,
    default_options,
):
    """
    Ensures using variables is fine.

    See:
    https://github.com/wemake-services/wemake-python-styleguide/issues/1115
    """
    tree = parse_ast_tree(code)

    visitor = BlockVariableVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, violations)
Exemplo n.º 10
0
def test_class_block_usage(
    assert_errors,
    parse_ast_tree,
    class_statement,
    context,
    variable_name,
    default_options,
):
    """Ensures using variables is fine."""
    code = context.format(
        class_statement.format(variable_name),
        'print({0})'.format(variable_name),
    )
    tree = parse_ast_tree(code)

    visitor = BlockVariableVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [])
def test_method_block_overlap(
    assert_errors,
    parse_ast_tree,
    function_statement,
    assign_and_annotation_statement,
    context,
    variable_name,
    default_options,
    mode,
):
    """Ensures that overlaping variables exist."""
    code = context.format(
        function_statement.format(variable_name),
        assign_and_annotation_statement.format(variable_name),
    )
    tree = parse_ast_tree(mode(code))

    visitor = BlockVariableVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [])
Exemplo n.º 12
0
def test_class_block_correct(
    assert_errors,
    parse_ast_tree,
    class_statement,
    assign_statement,
    context,
    first_name,
    second_name,
    default_options,
):
    """Ensures that different variables do not overlap."""
    code = context.format(
        class_statement.format(first_name),
        assign_statement.format(second_name),
    )
    tree = parse_ast_tree(code)

    visitor = BlockVariableVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [])
def test_reuse_overlap(
    assert_errors,
    parse_ast_tree,
    default_options,
    mode,
    block_statement,
    local_statement,
    first_name,
    second_name,
):
    """Ensures that overlapping variables exist no."""
    code = context.format(
        block_statement.format(first_name, second_name),
        local_statement.format(first_name, second_name),
    )
    tree = parse_ast_tree(mode(code))

    visitor = BlockVariableVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [BlockAndLocalOverlapViolation])
Exemplo n.º 14
0
def test_class_block_overlap(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    class_statement,
    assign_statement,
    context,
    variable_name,
    default_options,
):
    """Ensures that overlaping variables exist."""
    code = context.format(
        class_statement.format(variable_name),
        assign_statement.format(variable_name),
    )
    tree = parse_ast_tree(code)

    visitor = BlockVariableVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [BlockAndLocalOverlapViolation])
    assert_error_text(visitor, variable_name)