def test_correct_continue_usage( assert_errors, parse_ast_tree, code, default_options, mode, ): """Violations are not raised when `continue` is not the last statement.""" tree = parse_ast_tree(mode(code)) visitor = WrongLoopVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_wrong_while_loops( assert_errors, parse_ast_tree, keyword, template, default_options, ): """Testing while loops with wrong code.""" tree = parse_ast_tree(template.format(keyword)) visitor = WrongLoopVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [InfiniteWhileLoopViolation])
def test_wrong_continue_in_loop( assert_errors, parse_ast_tree, code, default_options, mode, ): """Violations are raised when `continue` is the last statement.""" tree = parse_ast_tree(mode(code)) visitor = WrongLoopVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [UselessContinueViolation])
def test_correct_while_loops( assert_errors, parse_ast_tree, keyword, template, default_options, ): """Testing while loops with correct code.""" tree = parse_ast_tree(template.format(keyword)) visitor = WrongLoopVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_correct_else_in_for_loop( assert_errors, parse_ast_tree, code, default_options, mode, ): """Violations are not raised when else without break statement.""" tree = parse_ast_tree(mode(code)) visitor = WrongLoopVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_wrong_else_in_for_loop( assert_errors, parse_ast_tree, code, default_options, mode, ): """Violations are raised when else with break statement.""" tree = parse_ast_tree(mode(code)) visitor = WrongLoopVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [RedundantLoopElseViolation])
def test_correct_multiline_loops( assert_errors, parse_ast_tree, code, default_options, mode, ): """Testing multiline loops.""" tree = parse_ast_tree(mode(code)) visitor = WrongLoopVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_lambda_body( assert_errors, parse_ast_tree, code, default_options, mode, ): """Ensures that lambda can not be inside a loop's body.""" tree = parse_ast_tree(mode(code)) visitor = WrongLoopVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [LambdaInsideLoopViolation])
def test_correct_lambda_body( assert_errors, parse_ast_tree, code, default_options, mode, ): """Ensures that lambda can be near loops.""" tree = parse_ast_tree(mode(code)) visitor = WrongLoopVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_correct_while_loops_function( assert_errors, parse_ast_tree, keyword, template, default_options, mode, ): """Testing while loops with ``return`` statements.""" tree = parse_ast_tree(mode(template.format(keyword))) visitor = WrongLoopVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])