コード例 #1
0
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,
    ])
コード例 #2
0
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, [])
コード例 #3
0
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])
コード例 #4
0
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])