def test_try_except_count_default( assert_errors, parse_ast_tree, default_options, ): """Testing that default settings raise a warning.""" tree = parse_ast_tree(complex_try_except) visitor = TryExceptVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [TooManyExceptCasesViolation])
def test_try_except_count_custom_settings( assert_errors, parse_ast_tree, code, default_options, ): """Testing that correct patterns work.""" tree = parse_ast_tree(code) visitor = TryExceptVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_try_body_count_default( assert_errors, parse_ast_tree, default_options, code, statements, ): """Testing that default settings raise a warning.""" tree = parse_ast_tree(code.format(statements)) visitor = TryExceptVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [TooLongTryBodyViolation])
def test_try_body_different_nodes( assert_errors, parse_ast_tree, default_options, code, statements, ): """Testing that default settings raise a warning.""" tree = parse_ast_tree(code.format(statements)) visitor = TryExceptVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_try_body_count_custom_options( assert_errors, parse_ast_tree, options, code, statements, ): """Testing that default settings raise a warning.""" tree = parse_ast_tree(code.format(statements)) option_values = options(max_try_body_length=2) visitor = TryExceptVisitor(option_values, tree=tree) visitor.run() assert_errors(visitor, [])
def test_try_body_wrong_custom_options( assert_errors, assert_error_text, parse_ast_tree, options, code, statements, ): """Testing that default settings raise a warning.""" tree = parse_ast_tree(code.format(statements)) option_values = options(max_try_body_length=1) visitor = TryExceptVisitor(option_values, tree=tree) visitor.run() assert_errors(visitor, [TooLongTryBodyViolation]) assert_error_text( visitor, '2', baseline=option_values.max_try_body_length, )