Skip to content

Commit

Permalink
Add test cases covering more lint-ignore directives
Browse files Browse the repository at this point in the history
Add a failing test to demonstrate decorator comment not respected

Add failing test to demonstrate comprehension comments not respected

Add failing test to demonstrate list element comments not respected

More test cases, label and split existing cases

Co-authored-by: Amethyst Reese <[email protected]>
  • Loading branch information
samueljsb and amyreese committed Apr 20, 2024
1 parent 5b1f9dd commit 5c1b514
Showing 1 changed file with 120 additions and 0 deletions.
120 changes: 120 additions & 0 deletions src/fixit/tests/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ def visit_Module(self, node: cst.Module) -> bool:

def visit_ClassDef(self, node: cst.ClassDef) -> bool:
self.report(node, "class def")
for d in node.decorators:
self.report(d, "class decorator")
return False

def visit_FunctionDef(self, node: cst.FunctionDef) -> bool:
if node.name.value == "problem":
self.report(node, "problem function")
return False

def visit_Pass(self, node: cst.Pass) -> bool:
Expand Down Expand Up @@ -280,6 +287,119 @@ class Foo(object):
"class def",
(5, 0),
),
(
# before function decorators
"""
import sys
# lint-fixme: ExerciseReport
@contextmanager
def problem():
yield True
""",
None,
None,
),
(
# after function decorators
"""
import sys
@contextmanager
# lint-fixme: ExerciseReport
def problem():
yield True
""",
None,
None,
),
(
# before class decorators
"""
import dataclasses
# lint-fixme: ExerciseReport
@dataclasses.dataclass
class C:
value = 1
""",
None,
None,
),
(
# after class decorators
"""
import dataclasses
@dataclasses.dataclass
# lint-fixme: ExerciseReport
class C:
value = 1
""",
None,
None,
),
(
# above comprehension
"""
# lint-fixme: ExerciseReport
[... for _ in range(1)]
""",
None,
None,
),
(
# inside comprehension
"""
[
# lint-fixme: ExerciseReport
... for _ in range(1)
]
""",
None,
None,
),
(
# after comprehension
"""
[... for _ in range(1)] # lint-fixme: ExerciseReport
""",
None,
None,
),
(
# trailing inline comprehension
"""
[
... for _ in range(1) # lint-fixme: ExerciseReport
]
""",
None,
None,
),
(
# before list element
"""
[
# lint-fixme: ExerciseReport
...,
None,
]
""",
None,
None,
),
(
# trailing list element
"""
[
..., # lint-fixme: ExerciseReport
None,
]
""",
None,
None,
),
):
idx += 1
content = dedent(code).encode("utf-8")
Expand Down

0 comments on commit 5c1b514

Please sign in to comment.