def test_useless_overwriting(
    assert_errors,
    parse_ast_tree,
    mode,
    code,
    statements,
    super_args,
    method_args,
    default_options,
):
    """Testing situations with useless overwriting."""
    formatted_code = mode(code.format(
        decorator='',
        args_definition=method_args.definition,
        statements=statements,
        super_args=super_args,
        method_name='function',
        args_invocation=method_args.invocation,
    ))
    tree = parse_ast_tree(formatted_code)

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

    assert_errors(visitor, [oop.UselessOverwrittenMethodViolation])
def test_useful_due_to_invalid_method_args(
    assert_errors,
    parse_ast_tree,
    mode,
    code,
    statements,
    super_args,
    method_args,
    default_options,
):
    """Testing situations with useful overwriting due to invalid method args."""
    formatted_code = mode(code.format(
        decorator='',
        args_definition=method_args.definition,
        statements=statements,
        super_args=super_args,
        method_name='function',
        args_invocation=method_args.invocation,
    ))
    tree = parse_ast_tree(formatted_code)

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

    assert_errors(visitor, [])
def test_init_generator(
    assert_errors,
    parse_ast_tree,
    default_options,
):
    """Testing that `__init__` with `yield` is prohibited."""
    tree = parse_ast_tree(init_with_yield)

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

    assert_errors(visitor, [YieldInsideInitViolation])
def test_function_without_arguments(
    assert_errors,
    parse_ast_tree,
    mode,
    default_options,
):
    """Testing that no arguments for method raises a violation."""
    tree = parse_ast_tree(mode(regular_function.format('')))

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

    assert_errors(visitor, [])
예제 #5
0
def test_sync_magic_used(
    assert_errors,
    parse_ast_tree,
    method,
    default_options,
):
    """Testing that any sync magic methods are working fine."""
    tree = parse_ast_tree(sync_method.format(method))

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

    assert_errors(visitor, [])
def test_magic_methods_regular(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that `__init__` without `yield` is allowed."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [])
def test_staticmethod_used(
    assert_errors,
    parse_ast_tree,
    default_options,
    mode,
):
    """Testing that some built-in functions are restricted as decorators."""
    tree = parse_ast_tree(mode(decorated_method.format('staticmethod')))

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

    assert_errors(visitor, [StaticMethodViolation])
def test_regular_decorator_used(
    assert_errors,
    parse_ast_tree,
    decorator,
    default_options,
    mode,
):
    """Testing that other decorators are allowed."""
    tree = parse_ast_tree(mode(decorated_method.format(decorator)))

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

    assert_errors(visitor, [])
예제 #9
0
def test_regular_method_used(
    assert_errors,
    parse_ast_tree,
    method,
    mode,
    default_options,
):
    """Testing that other methods are working fine."""
    tree = parse_ast_tree(mode(sync_method.format(method)))

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

    assert_errors(visitor, [])
def test_regular_method(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
    mode,
):
    """Testing that regular method with `yield` is allowed."""
    tree = parse_ast_tree(mode(code))

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

    assert_errors(visitor, [])
예제 #11
0
def test_correct_magic_method_used(
    assert_errors,
    parse_ast_tree,
    code,
    method,
    default_options,
):
    """Testing that some magic methods are working fine."""
    tree = parse_ast_tree(code.format(method))

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

    assert_errors(visitor, [])
예제 #12
0
def test_wrong_magic_used(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    method,
    default_options,
):
    """Testing that some magic methods are restricted."""
    tree = parse_ast_tree(magic_method.format(method))

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

    assert_errors(visitor, [BadMagicMethodViolation])
    assert_error_text(visitor, method)
def test_magic_statement(
    assert_errors,
    parse_ast_tree,
    default_options,
    code,
    method,
    statement,
):
    """Testing that magic method with statement is allowed."""
    tree = parse_ast_tree(code.format(method, statement))

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

    assert_errors(visitor, [])
def test_with_arguments(
    assert_errors,
    parse_ast_tree,
    code,
    arguments,
    mode,
    default_options,
):
    """Testing that other methods are working fine."""
    tree = parse_ast_tree(mode(code.format(arguments)))

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

    assert_errors(visitor, [])
def test_iter_generator(
    assert_errors,
    parse_ast_tree,
    default_options,
    code,
    method,
    statement,
):
    """Testing that magic `iter` method with `yield` is allowed."""
    tree = parse_ast_tree(code.format(method, statement))

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

    assert_errors(visitor, [])
def test_method_without_arguments(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    mode,
    default_options,
):
    """Testing that no arguments for method raises a violation."""
    tree = parse_ast_tree(mode(method_inside_class.format('')))

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

    assert_errors(visitor, [MethodWithoutArgumentsViolation])
    assert_error_text(visitor, 'some_name')
def test_magic_generator(
    assert_errors,
    parse_ast_tree,
    default_options,
    code,
    method,
    statement,
):
    """Testing that magic method with `yield` is prohibited."""
    tree = parse_ast_tree(code.format(method, statement))

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

    assert_errors(visitor, [YieldMagicMethodViolation])
def test_useful_due_to_incorrect_main_statement(
    assert_errors,
    parse_ast_tree,
    mode,
    code,
    args,
    statement,
    default_options,
):
    """Testing useful overwriting due to totally different body."""
    formatted_code = mode(code.format(args=args, statement=statement))
    tree = parse_ast_tree(formatted_code)

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

    assert_errors(visitor, [])