Example #1
0
def test_multiple_if_keywords_in_comprehension(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that using multiple `if` keywords is restricted."""
    tree = parse_ast_tree(code)
    visitor = WrongListComprehensionVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [MultipleIfsInComprehensionViolation])
Example #2
0
def test_if_keyword_in_comprehension(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that using `if` keyword is allowed."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [])
Example #3
0
def test_multiple_if_keywords_in_comprehension(
    assert_errors,
    parse_ast_tree,
    code,
    is_async,
    default_options,
):
    """Testing that using multiple `if` keywords is restricted."""
    if is_async:
        code = code.format(async_stmt='async ')
        code = code.lstrip()  # remove heading \n symbol
        code = async_wrapper.format(comprehension=code)
    else:
        code = code.format(async_stmt='')
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [MultipleIfsInComprehensionViolation])