def test_use_exception(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that `except Exception:` and `except:` are allowed."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [])
Пример #2
0
def test_correct_except_case(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Violations are not raised when using correct except case."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [])
def test_use_base_exception(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Testing that `except BaseException:` is restricted."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [BaseExceptionViolation])
Пример #4
0
def test_useless_except_case(
    assert_errors,
    parse_ast_tree,
    code,
    default_options,
):
    """Violations are raised when using wrong except case."""
    tree = parse_ast_tree(code)

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

    assert_errors(visitor, [UselessExceptCaseViolation])