Skip to content

Commit

Permalink
test: added a new test that checks that methods named get/set are all…
Browse files Browse the repository at this point in the history
…owed if not containing the name of a class attribute or instance attribute.

relates to #22
  • Loading branch information
fwald committed Feb 26, 2020
1 parent 3ff3817 commit 43c99e9
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/test_visitors/test_ast/test_classes/test_getter_setter.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ def {2}(self):
...
"""

class_mixed = """
class Test(object):
first: int
second = 2
third: int = 3
def __init__(self):
self.{0} = 5
def get_{1}(self):
...
def set_{2}(self):
...
"""


@pytest.mark.parametrize('code', [
module_getter_and_setter,
Expand Down Expand Up @@ -156,3 +172,30 @@ def test_instance_and_class_getter_setter(
visitor.run()

assert_errors(visitor, [UnpythonicGetterSetterViolation])


@pytest.mark.parametrize(('first', 'second', 'third'), [
('attribute', 'some', 'other'),
('_attribute', 'some', 'other'),
('__attribute', 'some', 'other'),
('attribute', 'some', 'some'),
('_attribute', 'some', 'some'),
('__attribute', 'some', 'some'),
])
def test_class_mixed(
assert_errors,
parse_ast_tree,
default_options,
first,
second,
third,
mode,
):
"""Testing that a mixture of instance and class attributes."""
test_instance = class_mixed.format(first, second, third)
tree = parse_ast_tree(mode(test_instance))

visitor = WrongClassVisitor(default_options, tree=tree)
visitor.run()

assert_errors(visitor, [])

0 comments on commit 43c99e9

Please sign in to comment.