def test_class_attributes_getter_setter( assert_errors, parse_ast_tree, default_options, attribute_name, access, annotation, method_name, assignment, mode, ): """Testing that using getter/setters with class attributes is prohibited.""" test_instance = class_attribute_template.format( access, attribute_name, assignment, annotation, method_name, ) tree = parse_ast_tree(mode(test_instance)) visitor = WrongClassBodyVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [UnpythonicGetterSetterViolation])
def test_nonmatching_class( assert_errors, parse_ast_tree, default_options, access, attribute_name, annotation, method_name, assignment, mode, ): """Testing that non matching attribute and getter/setter is allowed.""" test_instance = class_attribute_template.format( access, attribute_name, assignment, annotation, method_name, ) tree = parse_ast_tree(mode(test_instance)) visitor = WrongClassBodyVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_incorrect_body_items( assert_errors, parse_ast_tree, default_options, code, ): """Testing that incorrect body nodes are prohibited.""" tree = parse_ast_tree(class_body_template.format(code)) visitor = WrongClassBodyVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [WrongClassBodyContentViolation])
def test_valid_getter_and_setter( assert_errors, parse_ast_tree, default_options, code, mode, ): """Testing that correct usage of getter/setter is allowed.""" tree = parse_ast_tree(mode(code)) visitor = WrongClassBodyVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_body_correct_items( assert_errors, parse_ast_tree, code, default_options, mode, ): """Testing correct body items are allowed.""" tree = parse_ast_tree(mode(class_body_template.format(code))) visitor = WrongClassBodyVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])
def test_invalid_getter_and_setter( assert_errors, parse_ast_tree, default_options, code, mode, ): """Testing that wrong use of getter/setter is prohibited.""" tree = parse_ast_tree(mode(code)) visitor = WrongClassBodyVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [ UnpythonicGetterSetterViolation, UnpythonicGetterSetterViolation, ])
def test_class_mixed( assert_errors, parse_ast_tree, default_options, access, first, second, third, mode, ): """Testing correct use of methods with get/set in name.""" test_instance = class_mixed.format(access, first, second, third) tree = parse_ast_tree(mode(test_instance)) visitor = WrongClassBodyVisitor(default_options, tree=tree) visitor.run() assert_errors(visitor, [])