Esempio n. 1
0
def test_wrong_isinstance_conditions(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that correct conditions work."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [UnmergedIsinstanceCallsViolation])
Esempio n. 2
0
def test_regular_isinstance_conditions(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that correct conditions work."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [])
def test_duplicate_element_and_ternary(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that duplicates raise two violations."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [SameElementsInConditionViolation])
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 = BooleanConditionVisitor(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 = BooleanConditionVisitor(default_options, tree=tree)
    visitor.run()

    assert_errors(visitor, [ImplicitTernaryViolation])