Beispiel #1
0
def test_compare_with_mixed_in(
    assert_errors,
    parse_ast_tree,
    default_options,
):
    """Compares raise for multiple ``in`` and ``not in`` cases."""
    tree = parse_ast_tree('x in a not in b')

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

    assert_errors(visitor, [MultipleInCompareViolation])
def test_multi_item_container(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
    in_not_in,
):
    """Compares allow ``in`` with multi items containers."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [], ignored_types=WrongInCompareTypeViolation)
def test_compare_with_correct_type(
    assert_errors,
    parse_ast_tree,
    code,
    comparator,
    default_options,
):
    """Compares work correctly for ``in`` with correct types."""
    tree = parse_ast_tree(code.format(comparator))

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

    assert_errors(visitor, [])
def test_single_item_container(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
    in_not_in,
):
    """Compares forbid ``in`` with single item containers."""
    tree = parse_ast_tree(code)

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

    assert_errors(
        visitor,
        [InCompareWithSingleItemContainerViolation],
        ignored_types=WrongInCompareTypeViolation,
    )
def test_compare_with_wrong_type(
    assert_errors,
    parse_ast_tree,
    code,
    comparator,
    default_options,
):
    """Compares raise a violation for ``in`` with wrong types."""
    tree = parse_ast_tree(code.format(comparator))

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

    assert_errors(
        visitor,
        [WrongInCompareTypeViolation],
        ignored_types=(InCompareWithSingleItemContainerViolation,),
    )
Beispiel #6
0
def test_compare_with_multiple_in(
    assert_errors,
    parse_ast_tree,
    code,
    comparators,
    default_options,
    in_not_in,
):
    """Compares raise for multiple ``in`` cases."""
    tree = parse_ast_tree(in_not_in(code.format(*comparators)))

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

    assert_errors(
        visitor,
        [MultipleInCompareViolation],
        ignored_types=InCompareWithSingleItemContainerViolation,
    )
Beispiel #7
0
def test_compare_with_in(
    assert_errors,
    parse_ast_tree,
    code,
    comparators,
    default_options,
    in_not_in,
):
    """Compares work well for single ``in``."""
    tree = parse_ast_tree(in_not_in(code.format(*comparators)))

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

    assert_errors(
        visitor,
        [],
        ignored_types=(InCompareWithSingleItemContainerViolation, ),
    )