def test_regular_nodes(assert_errors, parse_ast_tree, code, default_options): """Testing that regular nodes do not raise violations.""" tree = parse_ast_tree(code) visitor = JonesComplexityVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_exact_complexity(parse_ast_tree, default_options, code, complexity): """Ensures that complexity is counted correctly.""" tree = parse_ast_tree(code) visitor = JonesComplexityVisitor(default_options, tree=tree) visitor.run() assert len(visitor._lines) == 1 # noqa: WPS437 assert len(visitor._lines[1]) == complexity # noqa: WPS437
def test_complex_lines(assert_errors, parse_ast_tree, code, options): """Testing that complex lines do raise violations.""" tree = parse_ast_tree(code) option_values = options(max_line_complexity=1) visitor = JonesComplexityVisitor(option_values, tree=tree) visitor.run() assert_errors(visitor, [LineComplexityViolation])
def test_module_score_error(assert_errors, parse_ast_tree, code, options): """Testing that regular nodes do raise violations.""" tree = parse_ast_tree(code) option_values = options(max_jones_score=-1) visitor = JonesComplexityVisitor(option_values, tree=tree) visitor.run() assert_errors(visitor, [JonesScoreViolation])
def test_that_some_nodes_are_ignored( parse_ast_tree, default_options, code, assert_errors, number_of_lines, ): """Ensures that complexity is counted correctly.""" tree = parse_ast_tree(code) visitor = JonesComplexityVisitor(default_options, tree=tree) visitor.run() assert len(visitor._lines) == number_of_lines # noqa: Z441
def test_same_complexity(parse_ast_tree, default_options): """Ensures that complexity is counted correctly.""" tree_without_types = parse_ast_tree(line_simple) tree_with_types = parse_ast_tree(line_with_types) simple_visitor = JonesComplexityVisitor( default_options, tree=tree_without_types, ) typed_visitor = JonesComplexityVisitor( default_options, tree=tree_with_types, ) simple_visitor.run() typed_visitor.run() assert len(simple_visitor._lines) == 1 # noqa: Z441 assert len(simple_visitor._lines[1]) == 3 # noqa: Z441 assert len(typed_visitor._lines[1]) == 3 # noqa: Z441