コード例 #1
0
def test_else_that_can_not_be_removed1(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that extra ``else`` blocks cannot be removed."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [])
コード例 #2
0
def test_else_that_can_be_removed_in_module(
    assert_errors,
    parse_ast_tree,
    template,
    code,
    default_options,
):
    """Testing that extra ``else`` blocks can be removed."""
    tree = parse_ast_tree(template.format(code, code))

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

    assert_errors(visitor, [UselessReturningElseViolation])
コード例 #3
0
def test_else_that_cannot_be_removed2(
    assert_errors,
    parse_ast_tree,
    code,
    returning,
    template,
    default_options,
    mode,
):
    """Testing that extra ``else`` blocks can be removed."""
    tree = parse_ast_tree(mode(template.format(code, returning)))

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

    assert_errors(visitor, [])
コード例 #4
0
def test_else_that_can_be_removed(
    assert_errors,
    parse_ast_tree,
    code1,
    code2,
    template,
    default_options,
    mode,
):
    """Testing that extra ``else`` blocks can be removed."""
    tree = parse_ast_tree(mode(template.format(code1, code2)))
    visitor = UselessElseVisitor(default_options, tree=tree)
    visitor.run()
    overrides = ['break']  # regression1958
    if code1 in overrides:
        # We might want to have an else statement
        # if the loop contains a break statement
        assert_errors(visitor, [])
    else:
        assert_errors(visitor, [UselessReturningElseViolation])