コード例 #1
0
def test_multiple_for_keywords_in_comprehension(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that using multiple `for` keywords is restricted."""
    tree = parse_ast_tree(code)
    visitor = WrongComprehensionVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [TooManyForsInComprehensionViolation])
コード例 #2
0
def test_regular_fors_in_comprehension(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that using two `for` keywords is allowed."""
    tree = parse_ast_tree(code)
    visitor = WrongComprehensionVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [])
コード例 #3
0
def test_comprehension_without_yield(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
    mode,
):
    """Testing that regular comprehensions are allowed."""
    tree = parse_ast_tree(mode(code.format('xy')))
    visitor = WrongComprehensionVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [])
コード例 #4
0
def test_yield_keyword_in_comprehension(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
    mode,
):
    """Testing that using `yield` keyword is not allowed."""
    tree = parse_ast_tree(mode(code.format('(yield xy)')))

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

    assert_errors(visitor, [YieldInComprehensionViolation])
コード例 #5
0
def test_if_keyword_in_comprehension(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
    mode,
):
    """Testing that using `if` keyword is allowed."""
    tree = parse_ast_tree(mode(code))

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

    assert_errors(visitor, [])