def test_no_violations_on_right_constants( assert_errors, parse_ast_tree, default_options, variable_value, ): """Ensures that usage of simple numbers allowed.""" tree = parse_ast_tree('a = {0}'.format(variable_value)) visitor = WrongNumberVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_violation_on_approximate_constants( assert_errors, assert_error_text, parse_ast_tree, default_options, variable_value, ): """Ensures that usage of approximate constants not allowed.""" tree = parse_ast_tree('my_const = {0}'.format(variable_value)) visitor = WrongNumberVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [ApproximateConstantViolation]) assert_error_text(visitor, str(variable_value))
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 = WrongNumberVisitor(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 = WrongNumberVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])