Пример #1
0
def test_comparison_wrong_order(
    assert_errors,
    parse_ast_tree,
    simple_conditions,
    comparators,
    default_options,
):
    """Comparisons raise for left constants."""
    tree = parse_ast_tree(simple_conditions.format(*comparators))

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

    assert_errors(visitor, [ComparisonOrderViolation])
Пример #2
0
def test_comparison_variables_in_special_case(
    assert_errors,
    parse_ast_tree,
    in_conditions,
    comparators,
    default_options,
):
    """Ensures that special case for `in` and `not in` is handled."""
    tree = parse_ast_tree(in_conditions.format(*comparators))

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

    assert_errors(visitor, [])
Пример #3
0
def test_comparison_variables(
    assert_errors,
    parse_ast_tree,
    simple_conditions,
    comparators,
    default_options,
):
    """Comparisons work well for left variables."""
    tree = parse_ast_tree(simple_conditions.format(*comparators))

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

    assert_errors(visitor, [])
Пример #4
0
def test_comparison_wrong_order_regression577(
    assert_errors,
    parse_ast_tree,
    default_options,
):
    """
    Ensures that `await` can be used in a comparision.

    See: https://github.com/wemake-services/wemake-python-styleguide/issues/577
    """
    tree = parse_ast_tree(regression577)

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

    assert_errors(visitor, [])
def test_comparison_wrong_order_multiple(
    assert_errors,
    parse_ast_tree,
    comparators,
    default_options,
):
    """Comparisons raise multiple issues for left constants."""
    tree = parse_ast_tree(
        'if {0} > {1} and {0} < {1}: ...'.format(*comparators), )

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

    assert_errors(visitor, [
        ComparisonOrderViolation,
        ComparisonOrderViolation,
    ])