Skip to content

Commit

Permalink
document new codemod and register it
Browse files Browse the repository at this point in the history
  • Loading branch information
clavedeluna committed Jan 19, 2024
1 parent cbf3550 commit 17d0b13
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
17 changes: 17 additions & 0 deletions integration_tests/test_fix_assert_tuple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from core_codemods.fix_assert_tuple import FixAssertTuple
from integration_tests.base_test import (
BaseIntegrationTest,
original_and_expected_from_code_path,
)


class TestFixAssertTuple(BaseIntegrationTest):
codemod = FixAssertTuple
code_path = "tests/samples/fix_assert_tuple.py"
original_code, expected_new_code = original_and_expected_from_code_path(
code_path, [(0, "assert 1 == 1\n"), (1, "assert 2 == 2\n")]
)
expected_diff = "--- \n+++ \n@@ -1 +1,2 @@\n-assert (1 == 1, 2 == 2)\n+assert 1 == 1\n+assert 2 == 2\n"
expected_line_change = "1"
change_description = FixAssertTuple.change_description
num_changes = 2
4 changes: 4 additions & 0 deletions src/codemodder/scripts/generate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ class DocMetadata:
importance="Low",
guidance_explained="Values compared to empty sequences should be verified in case they are falsy values that are not a sequence.",
),
"fix-assert-tuple": DocMetadata(
importance="Medium",
guidance_explained="We believe this change is safe and will not cause any issues.",
),
}


Expand Down
2 changes: 2 additions & 0 deletions src/core_codemods/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from .flask_enable_csrf_protection import FlaskEnableCSRFProtection
from .replace_flask_send_file import ReplaceFlaskSendFile
from .fix_empty_sequence_comparison import FixEmptySequenceComparison
from .fix_assert_tuple import FixAssertTuple

registry = CodemodCollection(
origin="pixee",
Expand Down Expand Up @@ -100,5 +101,6 @@
FlaskEnableCSRFProtection,
ReplaceFlaskSendFile,
FixEmptySequenceComparison,
FixAssertTuple,
],
)
11 changes: 11 additions & 0 deletions src/core_codemods/docs/pixee_python_fix-assert-tuple.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
An assertion on a non-empty tuple will always evaluate to `True` so it's likely to be written unintentionally. This codemod will write one assert statement for each item in the tuple.



The changes from this codemod look like this:

```diff
- assert (1 == 1, 2 == 2)
+ assert 1 == 1
+ assert 2 == 2
```
1 change: 0 additions & 1 deletion src/core_codemods/fix_assert_tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class FixAssertTuple(SimpleCodemod, NameResolutionMixin):
change_description = (
"Separate assertion on a populated tuple into multiple assert statements."
)
REFERENCES: list = ["#TODO"]

def leave_SimpleStatementLine(
self,
Expand Down
1 change: 1 addition & 0 deletions tests/samples/fix_assert_tuple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assert (1 == 1, 2 == 2)

0 comments on commit 17d0b13

Please sign in to comment.