Esempio n. 1
0
def test_magic_number(
    assert_errors,
    parse_ast_tree,
    code,
    number,
    default_options,
):
    """Testing that there are no magic numbers in this code."""
    tree = parse_ast_tree(code.format(number))

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

    assert_errors(visitor, [])
def test_magic_number_octal_warning(
    assert_errors,
    parse_ast_tree,
    code,
    number,
    default_options,
    mode,
):
    """Testing that magic numbers in this code are warnings."""
    tree = parse_ast_tree(mode(code.format(number)))

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

    assert_errors(visitor, [MagicNumberViolation])
def test_magic_number_whitelist(
    assert_errors,
    parse_ast_tree,
    code,
    number,
    default_options,
    mode,
):
    """Testing that magic numbers in this code are whitelisted."""
    tree = parse_ast_tree(mode(code.format(number)))

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

    assert_errors(visitor, [])