From adbd9560d43d146bdf49866dc3c1dd6ce960c158 Mon Sep 17 00:00:00 2001 From: Amethyst Reese Date: Fri, 19 Apr 2024 13:54:59 -0700 Subject: [PATCH] More test cases, label and split existing cases --- src/fixit/tests/rule.py | 87 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 79 insertions(+), 8 deletions(-) diff --git a/src/fixit/tests/rule.py b/src/fixit/tests/rule.py index 7104286f..e9b7a345 100644 --- a/src/fixit/tests/rule.py +++ b/src/fixit/tests/rule.py @@ -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 @@ -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 @@ -293,18 +325,50 @@ 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 ] @@ -312,14 +376,21 @@ class C: None, None, ), - ( # list elements + ( + # before list element """ [ # lint-fixme: ExerciseReport ..., None, ] - + """, + None, + None, + ), + ( + # trailing list element + """ [ ..., # lint-fixme: ExerciseReport None, @@ -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())