Exemplo n.º 1
0
def test_wrong_decorator_used(assert_errors, parse_ast_tree, default_options):
    """Testing that some built-in functions are restricted as decorators."""
    tree = parse_ast_tree('some_static = staticmethod(some_function)', )

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

    assert_errors(visitor, [WrongFunctionCallViolation])
Exemplo n.º 2
0
def test_regular_function_called(
    assert_errors, parse_ast_tree, good_function, code, default_options,
):
    """Testing that other functions are not restricted."""
    tree = parse_ast_tree(code.format(good_function))

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

    assert_errors(visitor, [])
Exemplo n.º 3
0
def test_wrong_function_called(
    assert_errors, parse_ast_tree, bad_function, code, default_options,
):
    """Testing that some built-in functions are restricted."""
    tree = parse_ast_tree(code.format(bad_function))

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

    assert_errors(visitor, [WrongFunctionCallViolation])
Exemplo n.º 4
0
def test_correct_super_call(
    assert_errors,
    parse_ast_tree,
    default_options,
    mode,
):
    """Testing that calling `super` in method is fine."""
    tree = parse_ast_tree(mode(correct_super_call))

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

    assert_errors(visitor, [])
def test_wrong_isinstance_tuple(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that isinstance is not callable with wrong types."""
    tree = parse_ast_tree(isinstance_call.format(code))

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

    assert_errors(visitor, [WrongIsinstanceWithTupleViolation])
def test_correct_isinstance_tuple(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that isinstance is callable with correct types."""
    tree = parse_ast_tree(isinstance_call.format(code))

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

    assert_errors(visitor, [])
Exemplo n.º 7
0
def test_different_argument(
    assert_errors,
    parse_ast_tree,
    argument,
    default_options,
):
    """Testing that passing non-boolean args is fine."""
    tree = parse_ast_tree(wrong_argument.format(argument))

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

    assert_errors(visitor, [])
Exemplo n.º 8
0
def test_correct_boolean_argument(
    assert_errors,
    parse_ast_tree,
    argument,
    default_options,
):
    """Testing that passing any arguments as keywords is fine."""
    tree = parse_ast_tree(correct_argument.format(argument))

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

    assert_errors(visitor, [])
Exemplo n.º 9
0
def test_wrong_boolean_argument(
    assert_errors,
    parse_ast_tree,
    argument,
    default_options,
):
    """Testing that passing booleans as positional args is restricted."""
    tree = parse_ast_tree(wrong_argument.format(argument))

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

    assert_errors(visitor, [BooleanPositionalArgumentViolation])
Exemplo n.º 10
0
def test_wrong_super_call(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
    mode,
):
    """Testing that calling `super` has limitations."""
    tree = parse_ast_tree(mode(code))

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

    assert_errors(visitor, [IncorrectSuperCallViolation])
Exemplo n.º 11
0
def test_double_wrong_super_call(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
    mode,
):
    """Testing that it is possible to have two violations with `super`."""
    tree = parse_ast_tree(mode(code))

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

    assert_errors(visitor, [
        IncorrectSuperCallViolation,
        IncorrectSuperCallViolation,
    ])
Exemplo n.º 12
0
def test_wrong_function_call_with_module(
    assert_errors,
    assert_error_text,
    parse_ast_tree,
    bad_module_and_function,
    code,
    default_options,
    mode,
):
    """Testing that a module.function() call can be restricted."""
    tree = parse_ast_tree(mode(code.format(bad_module_and_function)))

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

    assert_errors(visitor, [WrongFunctionCallViolation])
    assert_error_text(visitor, bad_module_and_function)
Exemplo n.º 13
0
def test_wrong_access_super_call_with_no_args(
    assert_errors,
    parse_ast_tree,
    code,
    arg,
    prop,
    default_options,
    mode,
):
    """Testing that calling `super` with incorrect access is restricted."""
    tree = parse_ast_tree(mode(code.format(arg, prop)))

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

    assert_errors(visitor, [
        WrongSuperCallAccessViolation,
    ])
Exemplo n.º 14
0
def test_single_boolean_argument_allowed(
    assert_errors,
    parse_ast_tree,
    argument,
    default_options,
):
    """Test calls with single boolean argument.

    Ensure boolean argument can be passed as positional argument when
    it is the only call's argument.

    """
    tree = parse_ast_tree(single_argument.format(argument))

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

    assert_errors(visitor, [])
Exemplo n.º 15
0
def test_wrong_three_boolean_argument(
    assert_errors,
    parse_ast_tree,
    argument,
    template,
    function,
    default_options,
):
    """Testing that passing any arguments as keywords is fine."""
    tree = parse_ast_tree(template.format(argument, function))

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

    assert_errors(visitor, [
        BooleanPositionalArgumentViolation,
        BooleanPositionalArgumentViolation,
        BooleanPositionalArgumentViolation,
    ])