def test_complex_cognitive_options( assert_errors, assert_error_text, parse_ast_tree, code, options, mode, ): """Ensures that complex can be modified via settings.""" tree = parse_ast_tree(mode(code)) option_values = options(max_cognitive_average=0) visitor = CognitiveComplexityVisitor(option_values, tree=tree) visitor.run() assert_errors( visitor, [CognitiveModuleComplexityViolation], ignored_types=(CognitiveComplexityViolation, ), ) assert_error_text( visitor, '1.0', option_values.max_cognitive_average, multiple=True, )
def test_complex_cognitive_function( assert_errors, assert_error_text, parse_ast_tree, code, default_options, mode, ): """Ensures that complex cognitive code does not work.""" tree = parse_ast_tree(mode(code)) visitor = CognitiveComplexityVisitor(default_options, tree=tree) visitor.run() assert_errors( visitor, [CognitiveComplexityViolation], ignored_types=(CognitiveModuleComplexityViolation, ), ) assert_error_text( visitor, '22', default_options.max_cognitive_score, multiple=True, )
def test_cognitive_average_default_options( assert_errors, parse_ast_tree, code, default_options, mode, ): """Ensures that simple cognitive code does work.""" tree = parse_ast_tree(mode(code)) visitor = CognitiveComplexityVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_complex_cognitive_module( assert_errors, parse_ast_tree, code, default_options, mode, ): """Ensures that complex cognitive code does not work.""" tree = parse_ast_tree(mode(code)) visitor = CognitiveComplexityVisitor(default_options, tree=tree) visitor.run() assert_errors( visitor, [CognitiveModuleComplexityViolation], ignored_types=(CognitiveComplexityViolation, ), )