Ejemplo n.º 1
0
def test_correct_constant_is(
    assert_errors,
    parse_ast_tree,
    comparators,
    is_conditions,
    default_options,
):
    """Testing that compares with falsy constants are not allowed."""
    tree = parse_ast_tree(is_conditions.format(*comparators))

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

    assert_errors(visitor, [])
Ejemplo n.º 2
0
def test_falsy_constant(
    assert_errors,
    parse_ast_tree,
    comparators,
    eq_conditions,
    default_options,
):
    """Testing that compares with falsy contants are not allowed."""
    tree = parse_ast_tree(eq_conditions.format(*comparators))

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

    assert_errors(visitor, [FalsyConstantCompareViolation])
Ejemplo n.º 3
0
def test_correct_constant_compare(
    assert_errors,
    parse_ast_tree,
    comparators,
    simple_conditions,
    default_options,
):
    """Testing that normal compares are allowed."""
    tree = parse_ast_tree(simple_conditions.format(*comparators))

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

    assert_errors(visitor, [], (WrongIsCompareViolation, ))
Ejemplo n.º 4
0
def test_wrong_constant_is(
    assert_errors,
    parse_ast_tree,
    comparators,
    is_conditions,
    default_options,
):
    """Testing that compares with falsy constants are not allowed."""
    tree = parse_ast_tree(is_conditions.format(*comparators))

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

    assert_errors(
        visitor,
        [WrongIsCompareViolation],
        ignored_types=FalsyConstantCompareViolation,
    )