Skip to content

Commit 3cfaa93

Browse files
committed
change codemod to use new api
1 parent b1fc362 commit 3cfaa93

3 files changed

Lines changed: 14 additions & 21 deletions

File tree

‎src/core_codemods/__init__.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,9 @@
4444
from .remove_debug_breakpoint import RemoveDebugBreakpoint
4545
from .combine_startswith_endswith import CombineStartswithEndswith
4646
from .fix_deprecated_logging_warn import FixDeprecatedLoggingWarn
47-
<<<<<<< HEAD
4847
from .flask_enable_csrf_protection import FlaskEnableCSRFProtection
4948
from .replace_flask_send_file import ReplaceFlaskSendFile
50-
=======
5149
from .fix_empty_sequence_comparison import FixEmptySequenceComparison
52-
>>>>>>> 00f4616 (document and fully test empty sequence comparison)
5350

5451
registry = CodemodCollection(
5552
origin="pixee",

‎src/core_codemods/fix_empty_sequence_comparison.py‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
import libcst as cst
2-
from codemodder.codemods.api import BaseCodemod, ReviewGuidance
2+
from core_codemods.api import Metadata, ReviewGuidance, SimpleCodemod, Reference
33
from codemodder.codemods.utils_mixin import NameResolutionMixin, AncestorPatternsMixin
44

55

66
class FixEmptySequenceComparison(
7-
BaseCodemod, NameResolutionMixin, AncestorPatternsMixin
7+
SimpleCodemod, NameResolutionMixin, AncestorPatternsMixin
88
):
9-
NAME = "fix-empty-sequence-comparison"
10-
SUMMARY = "Replace Comparisons to Empty Sequence with Implicit Boolean Comparison"
11-
REVIEW_GUIDANCE = ReviewGuidance.MERGE_WITHOUT_REVIEW
12-
DESCRIPTION = (
9+
metadata = Metadata(
10+
name="fix-empty-sequence-comparison",
11+
summary="Replace Comparisons to Empty Sequence with Implicit Boolean Comparison",
12+
review_guidance=ReviewGuidance.MERGE_AFTER_REVIEW,
13+
references=[
14+
Reference(
15+
url="https://docs.python.org/3/library/stdtypes.html#truth-value-testing"
16+
),
17+
],
18+
)
19+
change_description = (
1320
"Replace comparisons to empty sequence with implicit boolean comparison."
1421
)
15-
REFERENCES: list = []
1622

1723
def leave_Comparison(
1824
self, original_node: cst.Comparison, updated_node: cst.Comparison

‎tests/codemods/test_fix_empty_sequence_comparison.py‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ class TestFixEmptySequenceComparisonIfStatements(BaseCodemodTest):
7171
)
7272
def test_change_list(self, tmpdir, input_code, expected_output):
7373
self.run_and_assert(tmpdir, input_code, expected_output)
74-
assert len(self.file_context.codemod_changes) == 1
7574

7675
@pytest.mark.parametrize(
7776
"input_code,expected_output",
@@ -138,7 +137,6 @@ def test_change_list(self, tmpdir, input_code, expected_output):
138137
)
139138
def test_change_dict(self, tmpdir, input_code, expected_output):
140139
self.run_and_assert(tmpdir, input_code, expected_output)
141-
assert len(self.file_context.codemod_changes) == 1
142140

143141
@pytest.mark.parametrize(
144142
"input_code,expected_output",
@@ -205,7 +203,6 @@ def test_change_dict(self, tmpdir, input_code, expected_output):
205203
)
206204
def test_change_tuple(self, tmpdir, input_code, expected_output):
207205
self.run_and_assert(tmpdir, input_code, expected_output)
208-
assert len(self.file_context.codemod_changes) == 1
209206

210207
@pytest.mark.parametrize(
211208
"code",
@@ -229,7 +226,6 @@ def test_change_tuple(self, tmpdir, input_code, expected_output):
229226
)
230227
def test_no_change(self, tmpdir, code):
231228
self.run_and_assert(tmpdir, code, code)
232-
assert len(self.file_context.codemod_changes) == 0
233229

234230

235231
class TestFixEmptySequenceComparisonAssertStatements(BaseCodemodTest):
@@ -290,7 +286,6 @@ class TestFixEmptySequenceComparisonAssertStatements(BaseCodemodTest):
290286
)
291287
def test_change_list(self, tmpdir, input_code, expected_output):
292288
self.run_and_assert(tmpdir, input_code, expected_output)
293-
assert len(self.file_context.codemod_changes) == 1
294289

295290
@pytest.mark.parametrize(
296291
"input_code,expected_output",
@@ -347,7 +342,6 @@ def test_change_list(self, tmpdir, input_code, expected_output):
347342
)
348343
def test_change_dict(self, tmpdir, input_code, expected_output):
349344
self.run_and_assert(tmpdir, input_code, expected_output)
350-
assert len(self.file_context.codemod_changes) == 1
351345

352346
@pytest.mark.parametrize(
353347
"input_code,expected_output",
@@ -404,7 +398,6 @@ def test_change_dict(self, tmpdir, input_code, expected_output):
404398
)
405399
def test_change_tuple(self, tmpdir, input_code, expected_output):
406400
self.run_and_assert(tmpdir, input_code, expected_output)
407-
assert len(self.file_context.codemod_changes) == 1
408401

409402
@pytest.mark.parametrize(
410403
"code",
@@ -421,7 +414,6 @@ def test_change_tuple(self, tmpdir, input_code, expected_output):
421414
)
422415
def test_no_change(self, tmpdir, code):
423416
self.run_and_assert(tmpdir, code, code)
424-
assert len(self.file_context.codemod_changes) == 0
425417

426418

427419
@pytest.mark.xfail(
@@ -472,8 +464,7 @@ class TestFixEmptySequenceComparisonMultipleStatements(BaseCodemodTest):
472464
],
473465
)
474466
def test_change(self, tmpdir, input_code, expected_output):
475-
self.run_and_assert(tmpdir, input_code, expected_output)
476-
assert len(self.file_context.codemod_changes) == 2
467+
self.run_and_assert(tmpdir, input_code, expected_output, num_changes=2)
477468

478469

479470
class TestFixEmptySequenceComparisonAssignmentStatements(BaseCodemodTest):
@@ -514,4 +505,3 @@ class TestFixEmptySequenceComparisonAssignmentStatements(BaseCodemodTest):
514505
)
515506
def test_change(self, tmpdir, input_code, expected_output):
516507
self.run_and_assert(tmpdir, input_code, expected_output)
517-
assert len(self.file_context.codemod_changes) == 1

0 commit comments

Comments
 (0)