示例#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, [])
示例#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])
示例#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, ))
示例#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,
    )