-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5143749
commit 322399f
Showing
12 changed files
with
141 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from core_codemods.fix_assert_tuple import FixAssertTupleTransform | ||
from core_codemods.sonar.sonar_fix_assert_tuple import SonarFixAssertTuple | ||
from integration_tests.base_test import ( | ||
BaseIntegrationTest, | ||
original_and_expected_from_code_path, | ||
) | ||
|
||
|
||
class TestFixAssertTuple(BaseIntegrationTest): | ||
codemod = SonarFixAssertTuple | ||
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" | ||
sonar_issues_json = "tests/samples/sonar_issues.json" | ||
expected_line_change = "1" | ||
change_description = FixAssertTupleTransform.change_description | ||
num_changes = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from codemodder.codemods.base_codemod import Reference | ||
from codemodder.codemods.sonar import SonarCodemod | ||
from core_codemods.fix_assert_tuple import FixAssertTuple | ||
|
||
SonarFixAssertTuple = SonarCodemod.from_core_codemod( | ||
name="fix-assert-tuple-S5905", | ||
other=FixAssertTuple, | ||
rules=["python:S5905"], | ||
new_references=[ | ||
Reference(url="https://rules.sonarsource.com/python/type/Bug/RSPEC-5905/"), | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import json | ||
from core_codemods.sonar.sonar_fix_assert_tuple import SonarFixAssertTuple | ||
from tests.codemods.base_codemod_test import BaseSASTCodemodTest | ||
|
||
|
||
class TestSonarFixAssertTuple(BaseSASTCodemodTest): | ||
codemod = SonarFixAssertTuple | ||
tool = "sonar" | ||
|
||
def test_name(self): | ||
assert self.codemod.name == "fix-assert-tuple-S5905" | ||
|
||
def test_simple(self, tmpdir): | ||
input_code = """\ | ||
assert (1,2,3) | ||
""" | ||
expected_output = """\ | ||
assert 1 | ||
assert 2 | ||
assert 3 | ||
""" | ||
issues = { | ||
"issues": [ | ||
{ | ||
"rule": "python:S5905", | ||
"component": f"{tmpdir / 'code.py'}", | ||
"textRange": { | ||
"startLine": 1, | ||
"endLine": 1, | ||
"startOffset": 8, | ||
"endOffset": 15, | ||
}, | ||
} | ||
] | ||
} | ||
self.run_and_assert( | ||
tmpdir, | ||
input_code, | ||
expected_output, | ||
results=json.dumps(issues), | ||
num_changes=3, | ||
) |