示例#1
0
def test_nested_ternary(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that ternary can be used work well."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [NestedTernaryViolation])
def test_simplifiable_exp(
    assert_errors,
    parse_ast_tree,
    comparators,
    default_options,
):
    """Testing that compares can be simplified."""
    tree = parse_ast_tree(if_expression.format(*comparators))

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

    assert_errors(visitor, [SimplifiableIfViolation])
def test_not_simplifiable_node(
    assert_errors,
    parse_ast_tree,
    code,
    comparators,
    default_options,
):
    """Testing that regular nodes work well."""
    tree = parse_ast_tree(code.format(*comparators))

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

    assert_errors(visitor, [])
def test_not_simplifiable_node_multiple(
    assert_errors,
    parse_ast_tree,
    code,
    comparators,
    default_options,
):
    """Testing that simplifiable nodes work well with incorrect patterns."""
    tree = parse_ast_tree(code.format(*comparators))

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

    assert_errors(visitor, [])
示例#5
0
def test_useless(
    assert_errors,
    parse_ast_tree,
    code,
    comparators,
    default_options,
):
    """Testing that violations are when using invalid conditional."""
    tree = parse_ast_tree(create_variable.format(code.format(comparators)))

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

    assert_errors(visitor, [ConstantConditionViolation])
def test_valid_conditional(
    assert_errors,
    parse_ast_tree,
    code,
    comparators,
    default_options,
    mode,
):
    """Testing that conditionals work well."""
    tree = parse_ast_tree(
        mode(create_variable.format(code.format(comparators))), )

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

    assert_errors(visitor, [])