def test_bare_raise_inside_generators_yield_from( assert_errors, parse_ast_tree, code, statement, default_options, ): """Testing that bare `raise` is allowed inside generators.""" tree = parse_ast_tree(code.format(statement, '')) visitor = FunctionDefinitionVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_correct_function_defaults( assert_errors, parse_ast_tree, default_options, code, mode, ): """Testing that correct function defaults passes validation.""" tree = parse_ast_tree(mode(function_with_defaults.format(code))) visitor = FunctionDefinitionVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_wrong_function_defaults( assert_errors, parse_ast_tree, default_options, code, mode, ): """Testing that wrong function defaults are forbidden.""" tree = parse_ast_tree(mode(function_with_defaults.format(code))) visitor = FunctionDefinitionVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [ComplexDefaultValuesViolation])
def test_wrong_super_call( assert_errors, parse_ast_tree, code, default_options, mode, ): """Testing that naming and using variables have limitations.""" tree = parse_ast_tree(mode(code)) visitor = FunctionDefinitionVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [UnusedVariableIsUsedViolation])
def test_correct_variables( assert_errors, parse_ast_tree, default_options, code, mode, ): """Testing that correct usage of variables is allowed.""" tree = parse_ast_tree(mode(code)) visitor = FunctionDefinitionVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_method_decorators_incorrect( assert_errors, parse_ast_tree, code, default_options, mode, ): """Testing that too large amount of decorators works.""" tree = parse_ast_tree(mode(code)) visitor = FunctionDefinitionVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [WrongDescriptorDecoratorViolation])
def test_stop_iteration_in_generators_yield_from( assert_errors, parse_ast_tree, code, statement, exception, default_options, ): """Testing that `raise StopIteration` is restricted inside generators.""" tree = parse_ast_tree(code.format(statement, exception)) visitor = FunctionDefinitionVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [StopIterationInsideGeneratorViolation])
def test_other_exc_in_generators_yield_from( assert_errors, parse_ast_tree, code, statement, exception, default_options, ): """Testing that `raise` of other exceptions is allowed inside generators.""" tree = parse_ast_tree(code.format(statement, exception)) visitor = FunctionDefinitionVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_stop_iteration_inside_bare_functions( assert_errors, parse_ast_tree, code, statement, exception, default_options, mode, ): """Testing that `raise StopIteration` is allowed inside bare functions.""" tree = parse_ast_tree(mode(code.format(statement, exception))) visitor = FunctionDefinitionVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_double_wrong_variables( assert_errors, parse_ast_tree, default_options, mode, ): """Testing that it is possible to have two violations with wrong vars.""" tree = parse_ast_tree(mode(""" def some_function(): _should_not_be_used = 1 print(_should_not_be_used) print(_should_not_be_used) """)) visitor = FunctionDefinitionVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [ UnusedVariableIsUsedViolation, UnusedVariableIsUsedViolation, ])