diff --git a/python/testData/inspections/PyMethodOverridingInspection/ArgAndKwargs.py b/python/testData/inspections/PyMethodOverridingInspection/ArgAndKwargs.py new file mode 100644 index 000000000000..55640981864d --- /dev/null +++ b/python/testData/inspections/PyMethodOverridingInspection/ArgAndKwargs.py @@ -0,0 +1,8 @@ +class B: + def foo(self, **kwargs): + pass + + +class C(B): + def foo(self, arg1=None, **kwargs): # pass + pass diff --git a/python/testData/inspections/PyMethodOverridingInspection/ArgsKwargsAsAllowAnything.py b/python/testData/inspections/PyMethodOverridingInspection/ArgsKwargsAsAllowAnything.py new file mode 100644 index 000000000000..6058ba148c06 --- /dev/null +++ b/python/testData/inspections/PyMethodOverridingInspection/ArgsKwargsAsAllowAnything.py @@ -0,0 +1,28 @@ +class B1: + def foo(self, a, b): + pass + + +class C1(B1): + def foo(self, *b): + pass + + +class B2: + def foo(self, **kwargs): + pass + + +class C2(B2): + def foo(self): + pass + + +class B3: + def foo(self, *args): + pass + + +class C3(B3): + def foo(self): + pass diff --git a/python/testData/inspections/PyMethodOverridingInspection/ArgsKwargsOverrideArg.py b/python/testData/inspections/PyMethodOverridingInspection/ArgsKwargsOverrideArg.py new file mode 100644 index 000000000000..8cd9f0cf9d3c --- /dev/null +++ b/python/testData/inspections/PyMethodOverridingInspection/ArgsKwargsOverrideArg.py @@ -0,0 +1,23 @@ +class B: + def foo(self, a): + pass + + +class C1(B): + def foo(self, *a): + pass + + +class C2(B): + def foo(self): + pass + + +class C3(B): + def foo(self, **a): + pass + + +class C4(B): + def foo(self, a): + pass diff --git a/python/testData/inspections/PyMethodOverridingInspection/BothArgsKwargs.py b/python/testData/inspections/PyMethodOverridingInspection/BothArgsKwargs.py new file mode 100644 index 000000000000..82753b254177 --- /dev/null +++ b/python/testData/inspections/PyMethodOverridingInspection/BothArgsKwargs.py @@ -0,0 +1,23 @@ +class B1: + def foo(self, *args, **kwargs): + raise NotImplementedError() + + +class C1(B1): + def foo(self): # pass + pass + + +class C2(B1): + def foo(self, arg1): # pass + pass + + +class B3: + def foo(self, arg1, *args, **kwargs): + raise NotImplementedError() + + +class C3(B3): + def foo(self, arg1, arg2=None): # fail + pass diff --git a/python/testData/inspections/PyMethodOverridingInspection/DefaultArgument.py b/python/testData/inspections/PyMethodOverridingInspection/DefaultArgument.py new file mode 100644 index 000000000000..20a91efce66b --- /dev/null +++ b/python/testData/inspections/PyMethodOverridingInspection/DefaultArgument.py @@ -0,0 +1,8 @@ +class B: + def foo(self, arg1): + pass + + +class C(B): + def foo(self, arg1, arg2=None): #pass + pass diff --git a/python/testData/inspections/PyMethodOverridingInspection/ExtraKwargs.py b/python/testData/inspections/PyMethodOverridingInspection/ExtraKwargs.py new file mode 100644 index 000000000000..407d101ae98e --- /dev/null +++ b/python/testData/inspections/PyMethodOverridingInspection/ExtraKwargs.py @@ -0,0 +1,8 @@ +class B: + def foo(self, x=1): + pass + + +class C(B): + def foo(self, **kwargs): + pass diff --git a/python/testData/inspections/PyMethodOverridingInspection/InitNew.py b/python/testData/inspections/PyMethodOverridingInspection/InitNew.py new file mode 100644 index 000000000000..d97453e13b69 --- /dev/null +++ b/python/testData/inspections/PyMethodOverridingInspection/InitNew.py @@ -0,0 +1,20 @@ +class B: + def __init__(self): + pass + + def __new__(self): + pass + + def foo(self, a): + pass + + +class C(B): + def __init__(self, a): # different but ok because __init__ is special + pass + + def __new__(self, p, q): # different but ok because __new__ is special + pass + + def foo(self, s, t): + pass diff --git a/python/testData/inspections/PyMethodOverridingInspection/LessArgumentsPlusDefaults.py b/python/testData/inspections/PyMethodOverridingInspection/LessArgumentsPlusDefaults.py new file mode 100644 index 000000000000..4ef9eba27485 --- /dev/null +++ b/python/testData/inspections/PyMethodOverridingInspection/LessArgumentsPlusDefaults.py @@ -0,0 +1,8 @@ +class B: + def foo(self, arg1, arg2=None): + pass + + +class C(B): + def foo(self, arg1=None): #fail + pass diff --git a/python/testData/inspections/PyMethodOverridingInspection/LessParametersAndKwargs.py b/python/testData/inspections/PyMethodOverridingInspection/LessParametersAndKwargs.py new file mode 100644 index 000000000000..502b9f6ff6f3 --- /dev/null +++ b/python/testData/inspections/PyMethodOverridingInspection/LessParametersAndKwargs.py @@ -0,0 +1,8 @@ +class B: + def foo(self, arg1, arg2=None, arg3=None, arg4=None): + pass + + +class C(B): + def foo(self, arg1, arg2=None, arg3=None, **kwargs): #pass + pass diff --git a/python/testData/inspections/PyMethodOverridingInspection/NotOverridingMethod.py b/python/testData/inspections/PyMethodOverridingInspection/NotOverridingMethod.py new file mode 100644 index 000000000000..26e9f8324bd8 --- /dev/null +++ b/python/testData/inspections/PyMethodOverridingInspection/NotOverridingMethod.py @@ -0,0 +1,7 @@ +class B: + pass + + +class C(B): + def foo(self): + pass diff --git a/python/testData/inspections/PyMethodOverridingInspection/RequiredParameterAndKwargs.py b/python/testData/inspections/PyMethodOverridingInspection/RequiredParameterAndKwargs.py new file mode 100644 index 000000000000..f0cc84b532c1 --- /dev/null +++ b/python/testData/inspections/PyMethodOverridingInspection/RequiredParameterAndKwargs.py @@ -0,0 +1,9 @@ +class B: + def foo(self): + pass + + +class C(B): + def foo(self, p1, **kwargs): #fail + pass + diff --git a/python/testData/inspections/PyMethodOverridingInspection/test.py b/python/testData/inspections/PyMethodOverridingInspection/test.py deleted file mode 100644 index e03131da59ff..000000000000 --- a/python/testData/inspections/PyMethodOverridingInspection/test.py +++ /dev/null @@ -1,144 +0,0 @@ -class c1: - def foo(self, a): - pass - -class c2(c1): - def foo(self, *a): - pass - -class c3(c1): - def foo(self): - pass - -class c4(c1): - def foo(self, **a): - pass - -class c5(c1): - def foo(self, a): - pass - -class c6: - pass - -class c7(c6): - def foo(self): - pass - -class c8: - def __init__(self): - pass - - def __new__(self): - pass - - def foo(self, a): - pass - - -class c9(c8): - def __init__(self, a): # different but ok because __init__ is special - pass - - def __new__(self, p, q): # different but ok because __new__ is special - pass - - def foo(self, s, t): - pass - -class c10: - def foo(self, a, b): - pass - -class c11(c10): - def foo(self, *b): - pass - -class c12(c4): - def foo(self): - pass - -class c13: - def foo(self, *args): - pass - -class c14(c13): - def foo(self): - pass - -class c15: # PY-1083 - def foo(self, x = 1): - pass - -class c16: - def foo(self, **kwargs): - pass - - -# PY-6700 -class c17: - def foo(self, **kwargs): - pass - -class c18(c17): - def foo(self, arg1=None, **kwargs): # pass - pass - -class c19: - def foo(self, *args, **kwargs): - raise NotImplementedError() - -class c20(c19): - def foo(self): # pass - pass - -class c21(c19): - def foo(self, arg1): # pass - pass - -class c22: - def foo(self, arg1, *args, **kwargs): - raise NotImplementedError() - -class c23(c22): - def foo(self, arg1, arg2=None): # fail - pass - - -# PY-7157 -class c24: - def foo(self, arg1): - pass - -class c25(c24): - def foo(self, arg1, arg2=None): #pass - pass - - -# PY-7162 -class c26: - def foo(self, arg1, arg2=None): - pass - -class c27(c26): - def foo(self, arg1=None): #fail - pass - - -# PY-7159 -class c28: - def foo(self): - pass - -class c29(c28): - def foo(self, p1, **kwargs): #fail - pass - - -class c30: - def foo(self, arg1, arg2=None, arg3=None, arg4=None): - pass - -class c31(c30): - def foo(self, arg1, arg2=None, arg3=None, **kwargs): #pass - pass diff --git a/python/testSrc/com/jetbrains/python/PyMethodOverridingInspectionTest.java b/python/testSrc/com/jetbrains/python/PyMethodOverridingInspectionTest.java new file mode 100644 index 000000000000..ca385138cc4d --- /dev/null +++ b/python/testSrc/com/jetbrains/python/PyMethodOverridingInspectionTest.java @@ -0,0 +1,67 @@ +package com.jetbrains.python; + +import com.jetbrains.python.fixtures.PyTestCase; +import com.jetbrains.python.inspections.PyMethodOverridingInspection; + +/** + * @author vlan + */ +public class PyMethodOverridingInspectionTest extends PyTestCase { + private static final String TEST_DIRECTORY = "inspections/PyMethodOverridingInspection/"; + + public void testArgsKwargsOverrideArg() { + doTest(); + } + + public void testNotOverridingMethod() { + doTest(); + } + + public void testInitNew() { + doTest(); + } + + public void testArgsKwargsAsAllowAnything() { + doTest(); + } + + // PY-1083 + public void testExtraKwargs() { + doTest(); + } + + // PY-6700 + public void testBothArgsKwargs() { + doTest(); + } + + // PY-6700 + public void testArgAndKwargs() { + doTest(); + } + + // PY-7157 + public void testDefaultArgument() { + doTest(); + } + + // PY-7162 + public void testLessArgumentsPlusDefaults() { + doTest(); + } + + public void testLessParametersAndKwargs() { + doTest(); + } + + // PY-7159 + public void testRequiredParameterAndKwargs() { + doTest(); + } + + private void doTest() { + myFixture.configureByFile(TEST_DIRECTORY + getTestName(false) + ".py"); + myFixture.enableInspections(PyMethodOverridingInspection.class); + myFixture.checkHighlighting(true, false, false); + } +} diff --git a/python/testSrc/com/jetbrains/python/PythonAllTestsSuite.java b/python/testSrc/com/jetbrains/python/PythonAllTestsSuite.java index 7439dddfc5fa..4e0637f39e5e 100644 --- a/python/testSrc/com/jetbrains/python/PythonAllTestsSuite.java +++ b/python/testSrc/com/jetbrains/python/PythonAllTestsSuite.java @@ -95,6 +95,7 @@ public class PythonAllTestsSuite { PyUnresolvedReferencesInspectionTest.class, PyCallingNonCallableInspectionTest.class, PyUnboundLocalVariableInspectionTest.class, + PyMethodOverridingInspectionTest.class, PyUnusedImportTest.class, PyDeprecationTest.class, PythonHighlightingLexerTest.class, diff --git a/python/testSrc/com/jetbrains/python/PythonInspectionsTest.java b/python/testSrc/com/jetbrains/python/PythonInspectionsTest.java index 0ed83ce7872c..8af7f625bd8d 100644 --- a/python/testSrc/com/jetbrains/python/PythonInspectionsTest.java +++ b/python/testSrc/com/jetbrains/python/PythonInspectionsTest.java @@ -62,11 +62,6 @@ public class PythonInspectionsTest extends PyTestCase { doTest(getTestName(false), inspection); } - public void testPyMethodOverridingInspection() { - LocalInspectionTool inspection = new PyMethodOverridingInspection(); - doHighlightingTest(inspection); - } - public void testPyTrailingSemicolonInspection() { LocalInspectionTool inspection = new PyTrailingSemicolonInspection(); doTest(getTestName(false), inspection);