def test_iter_correct_type( assert_errors, parse_ast_tree, code, default_options, mode, ): """Ensures that correct types can be used as a loop's iter.""" tree = parse_ast_tree(mode(for_loop_template.format(code))) visitor = WrongLoopDefinitionVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_wrong_definition_loop( assert_errors, parse_ast_tree, definition, default_options, mode, ): """Ensures that wrong definitions are not allowed.""" tree = parse_ast_tree(mode(for_loop_def.format(definition))) visitor = WrongLoopDefinitionVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [LoopVariableDefinitionViolation])
def test_correct_definition_loop( assert_errors, parse_ast_tree, definition, default_options, mode, ): """Ensures that correct definitions are allowed.""" tree = parse_ast_tree(mode(for_loop_def.format(definition))) visitor = WrongLoopDefinitionVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_comprehension_without_bad_definitions( assert_errors, parse_ast_tree, code, definition, default_options, mode, ): """Testing that regular comprehensions are allowed.""" tree = parse_ast_tree(mode(code.format(definition))) visitor = WrongLoopDefinitionVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_correct_sync_for_loop( assert_errors, parse_ast_tree, code, template, default_options, ): """Ensures that correct ``for`` loops are allowed.""" tree = parse_ast_tree(template.format(code)) visitor = WrongLoopDefinitionVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_implicit_yield_from( assert_errors, parse_ast_tree, code, template, default_options, mode, ): """Ensures that implicit ``yield from`` are not allowed.""" tree = parse_ast_tree(mode(template.format(code))) visitor = WrongLoopDefinitionVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [ImplicitYieldFromViolation])
def test_wrong_definitions_in_comprehension( assert_errors, parse_ast_tree, code, definition, default_options, mode, ): """Testing that using wrong variables is not allowed.""" tree = parse_ast_tree(mode(code.format(definition))) visitor = WrongLoopDefinitionVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [LoopVariableDefinitionViolation])
def test_async_implicit_yield_from( assert_errors, parse_ast_tree, code, template, default_options, async_wrapper, ): """Ensures that implicit ``yield from`` in async functions are allowed.""" tree = parse_ast_tree(async_wrapper(template.format(code))) visitor = WrongLoopDefinitionVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_regular_loops( assert_errors, parse_ast_tree, code, template, default_options, mode, ): """Ensures that correct ``sum()`` calls are allowed.""" tree = parse_ast_tree(mode(template.format(code))) visitor = WrongLoopDefinitionVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_iter_incorrect_type( assert_errors, parse_ast_tree, code, template, default_options, mode, ): """Ensures that wrong types cannot be used as a loop's iter.""" tree = parse_ast_tree(mode(template.format(code))) visitor = WrongLoopDefinitionVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [WrongLoopIterTypeViolation])