-
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
f1a28ca
commit 8ba8f13
Showing
6 changed files
with
165 additions
and
13 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,38 @@ | ||
from core_codemods.sonar_numpy_nan_equality import ( | ||
SonarNumpyNanEquality, | ||
SonarNumpyNanEqualityTransformer, | ||
) | ||
from integration_tests.base_test import ( | ||
BaseIntegrationTest, | ||
original_and_expected_from_code_path, | ||
) | ||
|
||
|
||
class TestNumpyNanEquality(BaseIntegrationTest): | ||
codemod = SonarNumpyNanEquality | ||
code_path = "tests/samples/numpy_nan_equality.py" | ||
original_code, expected_new_code = original_and_expected_from_code_path( | ||
code_path, | ||
[ | ||
(3, """if np.isnan(a):\n"""), | ||
], | ||
) | ||
sonar_issues_json = "tests/samples/sonar_issues.json" | ||
|
||
# fmt: off | ||
expected_diff =( | ||
"""--- \n""" | ||
"""+++ \n""" | ||
"""@@ -1,5 +1,5 @@\n""" | ||
""" import numpy as np\n""" | ||
""" \n""" | ||
""" a = np.nan\n""" | ||
"""-if a == np.nan:\n""" | ||
"""+if np.isnan(a):\n""" | ||
""" pass\n""" | ||
) | ||
# fmt: on | ||
|
||
expected_line_change = "4" | ||
change_description = SonarNumpyNanEqualityTransformer.change_description | ||
num_changed_files = 1 |
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,41 @@ | ||
import json | ||
from core_codemods.sonar_numpy_nan_equality import SonarNumpyNanEquality | ||
from tests.codemods.base_codemod_test import BaseSASTCodemodTest | ||
from textwrap import dedent | ||
|
||
|
||
class TestSonarNumpyNanEquality(BaseSASTCodemodTest): | ||
codemod = SonarNumpyNanEquality | ||
tool = "sonar" | ||
|
||
def test_name(self): | ||
assert self.codemod.name == "numpy-nan-equality-S6725" | ||
|
||
def test_simple(self, tmpdir): | ||
input_code = """\ | ||
import numpy | ||
if a == numpy.nan: | ||
pass | ||
""" | ||
expected = """\ | ||
import numpy | ||
if numpy.isnan(a): | ||
pass | ||
""" | ||
issues = { | ||
"issues": [ | ||
{ | ||
"rule": "python:S6725", | ||
"component": f"{tmpdir / 'code.py'}", | ||
"textRange": { | ||
"startLine": 2, | ||
"endLine": 2, | ||
"startOffset": 3, | ||
"endOffset": 17, | ||
}, | ||
} | ||
] | ||
} | ||
self.run_and_assert( | ||
tmpdir, dedent(input_code), dedent(expected), results=json.dumps(issues) | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.