def test_range_len(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that ``range(len(...))`` cannot be used."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [ImplicitEnumerateViolation])
def test_correct_range_len(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that ``range()`` can be used."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [])
def test_regular_functions(
    assert_errors,
    parse_ast_tree,
    code,
    call,
    default_options,
    mode,
):
    """Testing that regular calls work."""
    tree = parse_ast_tree(mode(code.format(call)))

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

    assert_errors(visitor, [])
def test_open_inside_context_manager(
    assert_errors,
    parse_ast_tree,
    code,
    call,
    default_options,
    mode,
):
    """Testing that ``open()`` inside a context manager works."""
    tree = parse_ast_tree(mode(code.format(call)))

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

    assert_errors(visitor, [])
def test_open_without_context_manager(
    assert_errors,
    parse_ast_tree,
    code,
    call,
    default_options,
    mode,
):
    """Testing that ``open()`` without context managers raise a violation."""
    tree = parse_ast_tree(mode(code.format(call)))

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

    assert_errors(visitor, [OpenWithoutContextManagerViolation])
Exemple #6
0
def test_type_regular_usage(
    assert_errors,
    parse_ast_tree,
    code,
    call,
    default_options,
    mode,
):
    """Testing that ``type()`` can be used."""
    tree = parse_ast_tree(mode(code.format(call)))

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

    assert_errors(visitor, [])
Exemple #7
0
def test_type_with_compare(
    assert_errors,
    parse_ast_tree,
    code,
    call,
    default_options,
    mode,
):
    """Testing that ``type()`` cannot be used inside a compare."""
    tree = parse_ast_tree(mode(code.format(call)))

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

    assert_errors(visitor, [TypeCompareViolation])