Skip to content

Commit

Permalink
SONARPY-2284 Add tests for S2638 on imported class with decorator (#2130
Browse files Browse the repository at this point in the history
)
  • Loading branch information
thomas-serre-sonarsource authored Nov 6, 2024
1 parent db907a1 commit ad5c9c9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@
*/
package org.sonar.python.checks;

import java.util.List;
import org.junit.jupiter.api.Test;
import org.sonar.python.checks.utils.PythonCheckVerifier;

class ChangeMethodContractCheckTest {

@Test
void test() {
PythonCheckVerifier.verify("src/test/resources/checks/changeMethodContract.py", new ChangeMethodContractCheck());
PythonCheckVerifier.verify(
List.of("src/test/resources/checks/changeMethodContract.py", "src/test/resources/checks/changeMethodContractParent.py"),
new ChangeMethodContractCheck()
);
}
}
16 changes: 1 addition & 15 deletions python-checks/src/test/resources/checks/changeMethodContract.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
class ParentClass(object):
def __init__(p1, p2): ...
def compliant(self, param1): ...
def my_method(self, param1): ...
def with_default(self, param1=42): ...
def changed_param_order(self, param1, param2): ...
def with_keyword_only(self, param1, *, param2): ...
def with_kwargs(self, param1, **kwargs): ...
@foo
def with_decorator(self, param1): ...
def __private_method(self): ...
def using_tuple(self, (a, b)): ...
def positional_only(self, param1, /, param2, *, param3): ...
def with_two_keyword_only(self, *, param1, param2): ...
attr = 42
from changeMethodContractParent import ParentClass

class ChildClass(ParentClass):
def __init__(p1, p2, p3): ... # OK
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class ParentClass(object):
def __init__(p1, p2): ...
def compliant(self, param1): ...
def my_method(self, param1): ...
def with_default(self, param1=42): ...
def changed_param_order(self, param1, param2): ...
def with_keyword_only(self, param1, *, param2): ...
def with_kwargs(self, param1, **kwargs): ...
@foo
def with_decorator(self, param1): ...
def __private_method(self): ...
def using_tuple(self, (a, b)): ...
def positional_only(self, param1, /, param2, *, param3): ...
def with_two_keyword_only(self, *, param1, param2): ...
attr = 42

0 comments on commit ad5c9c9

Please sign in to comment.