def test_divide_by_one(
    assert_errors,
    parse_ast_tree,
    expression,
    default_options,
):
    """Testing an error when we divide by one."""
    tree = parse_ast_tree(expression)

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

    assert_errors(visitor, [MeaninglessNumberOperationViolation])
def test_meaningless_math(
    assert_errors,
    parse_ast_tree,
    expression,
    default_options,
):
    """Testing that there is no useless zero div."""
    tree = parse_ast_tree(usage_template.format(expression))

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

    assert_errors(visitor, [MeaninglessNumberOperationViolation])
def test_one_to_divide(
    assert_errors,
    parse_ast_tree,
    expression,
    default_options,
):
    """Testing that `1 / any number` is the correct expression."""
    tree = parse_ast_tree(expression)

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

    assert_errors(visitor, [])
def test_correct_zero_div(
    assert_errors,
    parse_ast_tree,
    expression,
    default_options,
):
    """Testing that there is no useless zero div."""
    tree = parse_ast_tree(usage_template.format(expression))

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

    assert_errors(visitor, [])
Exemple #5
0
def test_zero_mod(
    assert_errors,
    parse_ast_tree,
    expression,
    default_options,
):
    """Testing that useless modulus with zero are forbidden."""
    tree = parse_ast_tree(usage_template.format(expression))

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

    assert_errors(visitor, [ZeroDivisionViolation])
Exemple #6
0
def test_correct_zero_mod(
    assert_errors,
    parse_ast_tree,
    expression,
    default_options,
):
    """Testing that non-zero modulus operations are allowed."""
    tree = parse_ast_tree(usage_template.format(expression))

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

    assert_errors(visitor, [])
def test_useful_math(
    assert_errors,
    parse_ast_tree,
    expression,
    default_options,
):
    """Testing that useful math operations are allowed."""
    tree = parse_ast_tree(usage_template.format(expression))

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

    assert_errors(visitor, [])
Exemple #8
0
def test_plus_sign_before_numbers_valid(
    assert_errors,
    parse_ast_tree,
    code,
    number,
    default_options,
    mode,
):
    """Testing that there is no useless plus sign before a number."""
    tree = parse_ast_tree(mode(code.format(number)))

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

    assert_errors(visitor, [])