def test_unreachable_code_return(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that unreachable code is detected."""
    tree = parse_ast_tree(code.format('return', 'print()'))

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

    assert_errors(visitor, [UnreachableCodeViolation])
def test_regular_lines(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing correct order of lines is allowed."""
    tree = parse_ast_tree(code.format('print()', 'raise ValueError()'))

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

    assert_errors(visitor, [])
def test_correct_swapped_variables(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that correctly swapped variables."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [])
def test_wrong_swapped_variables(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Ensures that incorrectly swapped variables are forbidden."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [AlmostSwappedViolation])
def test_statement_with_useless_docstring(
    assert_errors,
    parse_ast_tree,
    code,
    statement,
    default_options,
):
    """Testing that docstring works."""
    tree = parse_ast_tree(code.format(statement))

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

    assert_errors(visitor, [StatementHasNoEffectViolation])
def test_statement_with_await_effect(
    assert_errors,
    parse_ast_tree,
    code,
    statement,
    default_options,
):
    """Testing that `await` works."""
    tree = parse_ast_tree(code.format(statement))

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

    assert_errors(visitor, [])
def test_statement_with_regular_effect(
    assert_errors,
    parse_ast_tree,
    code,
    statement,
    default_options,
):
    """Testing functions, methods, and assignment works."""
    tree = parse_ast_tree(code.format(statement))

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

    assert_errors(visitor, [])
def test_misrefactored_assignment(
    assert_errors,
    parse_ast_tree,
    code,
    statement,
    default_options,
):
    """Testing that unreachable code is detected."""
    tree = parse_ast_tree(code.format(statement))

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

    assert_errors(visitor, [MisrefactoredAssignmentViolation])
def test_statement_with_no_effect(
    assert_errors,
    parse_ast_tree,
    code,
    statement,
    default_options,
):
    """Testing that unreachable code is detected."""
    tree = parse_ast_tree(code.format(statement))

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

    assert_errors(visitor, [StatementHasNoEffectViolation])
Пример #10
0
def test_useless_loop_nodes(
    assert_errors,
    parse_ast_tree,
    code,
    statement,
    default_options,
    mode,
):
    """Ensures that useless loop nodes are forbidden."""
    tree = parse_ast_tree(mode(code.format(statement)))

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

    assert_errors(visitor, [UselessNodeViolation])
Пример #11
0
def test_useful_nodes(
    assert_errors,
    parse_ast_tree,
    code,
    statement,
    default_options,
    mode,
):
    """Ensures that useful nodes are required."""
    tree = parse_ast_tree(mode(code.format(statement)))

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

    assert_errors(visitor, [])