예제 #1
0
def test_regular_short_compare(
    code,
    assert_errors,
    parse_ast_tree,
    default_options,
):
    """Testing implicit complex compare."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [])
예제 #2
0
def test_implicit_complex_compare(
    code,
    comparators,
    assert_errors,
    parse_ast_tree,
    default_options,
):
    """Testing implicit complex compare."""
    tree = parse_ast_tree(code.format(*comparators))

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

    assert_errors(visitor, [ImplicitComplexCompareViolation])
def test_regular_compare_not_ternary(
    code,
    first,
    second,
    assert_errors,
    parse_ast_tree,
    default_options,
):
    """Testing regular compares and not ternaries."""
    tree = parse_ast_tree(code.format(first, second))

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

    assert_errors(visitor, [])
def test_implicit_ternary(
    code,
    first,
    second,
    assert_errors,
    parse_ast_tree,
    default_options,
):
    """Testing implicit ternary."""
    tree = parse_ast_tree(code.format(first, second))

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

    assert_errors(visitor, [ImplicitTernaryViolation])
예제 #5
0
def test_wrong_patterns_in_values(
    code,
    first,
    second,
    assert_errors,
    parse_ast_tree,
    default_options,
):
    """Testing safe in patterns."""
    tree = parse_ast_tree(code.format(first, second))

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

    assert_errors(visitor, [ImplicitInConditionViolation])
예제 #6
0
def test_different_in_values(
    code,
    first,
    second,
    assert_errors,
    parse_ast_tree,
    default_options,
):
    """Testing regular conditions."""
    tree = parse_ast_tree(code.format(first, second))

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

    assert_errors(visitor, [])