Skip to content

Commit

Permalink
More test cases, label and split existing cases
Browse files Browse the repository at this point in the history
  • Loading branch information
amyreese committed Apr 20, 2024
1 parent 650af28 commit adbd956
Showing 1 changed file with 79 additions and 8 deletions.
87 changes: 79 additions & 8 deletions src/fixit/tests/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ def visit_ClassDef(self, node: cst.ClassDef) -> bool:
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:
self.report(node, "I pass")
return False
Expand Down Expand Up @@ -281,7 +286,34 @@ class Foo(object):
"class def",
(5, 0),
),
( # class decorators
(
# 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
Expand All @@ -293,33 +325,72 @@ class C:
None,
None,
),
( # comprehensions
(
# 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,
),
( # list elements
(
# before list element
"""
[
# lint-fixme: ExerciseReport
...,
None,
]
""",
None,
None,
),
(
# trailing list element
"""
[
..., # lint-fixme: ExerciseReport
None,
Expand All @@ -331,7 +402,7 @@ class C:
):
idx += 1
content = dedent(code).encode("utf-8")
with self.subTest(f"test case {idx}"):
with self.subTest(f"test ignore {idx}"):
runner = LintRunner(Path("fake.py"), content)
violations = list(
runner.collect_violations([ExerciseReportRule()], Config())
Expand Down

0 comments on commit adbd956

Please sign in to comment.