finish splitting test data for PyArgumentListInspection

This commit is contained in:
Dmitry Jemerov
2011-08-30 17:56:16 +02:00
parent 06bc7c1311
commit 0fc37dd4de
15 changed files with 309 additions and 205 deletions
@@ -0,0 +1,4 @@
def baddeco(): pass
<warning descr="Function 'baddeco' lacks a positional argument">@baddeco</warning>
def f21(): pass
@@ -0,0 +1,55 @@
# bad argument list samples
class A:
def foo(self, x, y):
pass
# no self, but so what
def bar(one, two):
pass
a = A()
a.foo(1,2)
a.bar(<warning descr="Parameter 'two' unfilled">)</warning>;
def f1():
pass
f1()
f1(<warning descr="Unexpected argument">1</warning>)
f1(<warning descr="Unexpected argument">a = 1</warning>)
def f2(a):
pass
f2(<warning descr="Parameter 'a' unfilled">)</warning> # ok, fail
f2(1) # ok, pass
f2(1, <warning descr="Unexpected argument">2</warning>) # ok, fail
f2(a = 1) # ok, pass
f2(<warning descr="Unexpected argument">b = 1</warning><warning descr="Parameter 'a' unfilled">)</warning> # ok, fail
f2(a = 1, <warning descr="Unexpected argument">b = 2</warning>) # ok, fail
def f3(a, b):
pass
f3(1, 2)
f3(1, 2, <warning descr="Unexpected argument">3</warning>)
f3(b=2, a=1)
f3(b=1, <warning descr="Duplicate argument">b=2</warning>, a=1)
f3(1, b=2)
f3(a=1, <warning descr="Cannot appear past keyword arguments or *arg or **kwarg">2</warning><warning descr="Parameter 'b' unfilled">)</warning>
def f4(a, *b):
pass
f4(1)
f4(1, 2)
f4(1, 2, 3)
f4(1, *(2, 3))
f4(*(1,2,3))
f4(a=1, <warning descr="Cannot appear past keyword arguments or *arg or **kwarg">2</warning>, <warning descr="Cannot appear past keyword arguments or *arg or **kwarg">3</warning>)
@@ -0,0 +1,9 @@
class Payout:
@classmethod
def create(cls, teacher_id, entries):
payout = cls()
# payout.teacher = Teacher(teacher_id)
payout.save() # ok
def save(self):
pass
@@ -0,0 +1,70 @@
def deco(param):
pass
@deco # ok
def f6():
pass
@deco(1) # ok
def f7():
pass
@deco(<warning descr="Parameter 'param' unfilled">)</warning> # fail: missing param
def f8():
pass
@deco(1, <warning descr="Unexpected argument">2</warning>) # fail: extra param
def f9():
pass
def deco2(p1, p2): pass
<warning descr="Parameter 'p2' unfilled">@deco2 # fail: missing p2</warning>
def f10():
pass
@deco2(1<warning descr="Parameter 'p2' unfilled">)</warning> # fail: missing p2
def f11():
pass
@deco2(1, 2) # ok
def f12():
pass
@deco2(p2=2, p1=1) # ok
def f13():
pass
class Dec:
def __init__(self, param):
pass
@Dec # ok
def f14():
pass
@Dec(param=1) # ok
def f15():
pass
@Dec(<warning descr="Parameter 'param' unfilled">)</warning> # fail: missing param
def f16():
pass
class Dec2:
def __init__(self, p1, p2):
pass
@Dec2(<warning descr="Parameter 'p2' unfilled"><warning descr="Parameter 'p1' unfilled">)</warning></warning> # fail: no p1, p2
def f17():
pass
<warning descr="Parameter 'p2' unfilled">@Dec2 # fail: no p2</warning>
def f18():
pass
@Dec2(1, 2) # ok
def f19():
pass
@@ -1,195 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>badarglist.py</file>
<line>14</line>
<description>Parameter 'two' unfilled</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>21</line>
<description>Unexpected argument</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>22</line>
<description>Unexpected argument</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>29</line>
<description>Parameter 'a' unfilled</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>31</line>
<description>Unexpected argument</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>33</line>
<description>Unexpected argument</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>33</line>
<description>Parameter 'a' unfilled</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>34</line>
<description>Unexpected argument</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>41</line>
<description>Unexpected argument</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>43</line>
<description>Duplicate argument</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>45</line>
<description>Cannot appear past keyword arguments or *arg or **kwarg</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>45</line>
<description>Parameter 'b' unfilled</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>55</line>
<description>Cannot appear past keyword arguments or *arg or **kwarg</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>55</line> <!-- yes, two identical problems on same line -->
<description>Cannot appear past keyword arguments or *arg or **kwarg</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>65</line>
<description>Unexpected argument</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>66</line>
<description>Unexpected argument</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>80</line>
<description>Parameter 'param' unfilled</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>84</line>
<description>Unexpected argument</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>90</line>
<description>Parameter 'p2' unfilled</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>94</line>
<description>Parameter 'p2' unfilled</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>119</line>
<description>Parameter 'param' unfilled</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>128</line>
<description>Parameter 'p1' unfilled</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>128</line>
<description>Parameter 'p2' unfilled</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>132</line>
<description>Parameter 'p2' unfilled</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>145</line>
<description>Unexpected argument</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>158</line>
<description>Function 'baddeco' lacks a positional argument</description>
</problem>
<!--
<problem>
<file>badarglist.py</file>
<line>172</line>
<description>This argument list cannot be analyzed</description>
</problem>
-->
<problem>
<file>badarglist.py</file>
<line>211</line>
<description>Duplicate argument</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>212</line>
<description>More arguments than positional parameters left</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>213</line>
<description>Expected a sequence, got int</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>214</line>
<description>Parameter 'c' unfilled</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>227</line>
<description>Cannot appear past keyword arguments or *arg or **kwarg</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>232</line>
<description>Duplicate argument</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>233</line>
<description>Duplicate argument</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>236</line>
<description>Duplicate argument</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>237</line>
<description>Duplicate argument</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>238</line>
<description>Unexpected argument</description>
</problem>
<problem>
<file>badarglist.py</file>
<line>243</line>
<description>Duplicate argument</description>
</problem>
</problems>
@@ -0,0 +1,6 @@
class Baz:
def long_unique_identifier(self): pass
def xyzzy(baz):
baz.long_unique_identifier(1, 2, 3) # don't perform validation for implicit resolve results
@@ -0,0 +1,7 @@
class Foo:
def __init__(self, name):
print name
class Bar(Foo):
def __init__(self, name):
Foo.__init__(self, name) #ok
@@ -0,0 +1,9 @@
def f5(a, b, c):
pass
arg = [1, 2, 3]
kwarg = {'c':3}
f5(*arg, **kwarg) # ok
f5(1,2, **kwarg) # ok
f5(1, 2, 3, <warning descr="Unexpected argument">**kwarg</warning>) # fail
f5(1, 2, 3, <warning descr="Unexpected argument">*arg</warning>) # fail
@@ -0,0 +1,6 @@
class Py845:
def xyzzy(self): pass
def x(p):
if isinstance(p, Py845):
p.xyzzy()
@@ -0,0 +1,38 @@
def f(a, b, c):
pass
f(c=1, *(10, 20))
f(*(10, 20), c=1)
f(*(10, 20, 30), <warning descr="Duplicate argument">c=1</warning>) # fail: duplicate c
f(1, <warning descr="More arguments than positional parameters left">*(10, 20, 30)</warning>) # fail: tuple too long
f(1, <warning descr="Expected a sequence, got int">*(10)</warning>) # fail: wrong type
f(1, *(10,)<warning descr="Parameter 'c' unfilled">)</warning> # fail: tuple too short, c not mapped
def f1(a, b, c=1):
return a,b,c
f1(c=3, *(1, 2))
def f2(a, b, c=1, *d):
return a,b,c,d
f2(c=3, *(1,2))
f2(1,2,3, *(1,2))
f2(*(1,2), c=20)
f2(*(1,2), <warning descr="Cannot appear past keyword arguments or *arg or **kwarg">20</warning>) # fail: positional past *
def f3(a=1, b=2, c=3, *d):
return a,b,c,d
f3(c=3, <warning descr="Duplicate argument">a=1</warning>, b=2, *(1,2)) # fail: a twice
f3(1, 2, *(3,), <warning descr="Duplicate argument">c=4</warning>) # fail: c twice
f3(1,2,3, *(1,2))
f3(c=3, *(1,2)) #
f3(1, <warning descr="Duplicate argument">c=3</warning>, *(1,2)) # fail: c twice
f3(c=3, <warning descr="Duplicate argument">a=1</warning>, b=2, *(1,2)) # fail: a twice, no positinals
f3(c=3, a=1, b=2, <warning descr="Unexpected argument">d=(1,2)</warning>) # fail: unexpected d
f3(1, c=3, *(10,)) # ZZZ
f3(1, *(10,))
f3(1, *(10,), c=20)
f3(*(1,2), c=20)
f3(*(1,2), <warning descr="Duplicate argument">a=20</warning>) # fail: a twice
@@ -0,0 +1,17 @@
class Foo(object):
def __init__(self, color):
self.color = color
class Bar(object):
fooFactory = Foo
def quux(self):
foo = self.fooFactory("orange") # ok
class Foo:
def __init__(self, name):
print name
class Bar(Foo):
def __init__(self, name):
Foo.__init__(self, name)
Foo("Foo") # pass
@@ -0,0 +1,27 @@
def keywordonly_sum(*, k1=0, k2):
return k1 + k2
keywordonly_sum(k2=1)
keywordonly_sum(k1=1, k2=2)
keywordonly_sum(<warning descr="Parameter 'k2' unfilled">)</warning>
keywordonly_sum(<warning descr="Unexpected argument">1</warning>, <warning descr="Unexpected argument">2</warning><warning descr="Parameter 'k2' unfilled">)</warning>
def namedpast(*args, foo=None):
pass
namedpast(1,2,3, foo='a') # pass
namedpast(*args, foo='b') # pass
namedpast(foo='c') # pass
namedpast() # pass
namedpast(foo='1', <warning descr="Cannot appear past keyword arguments or *arg or **kwarg">2</warning>) # fail
def a23(a, *b, c=1):
pass
a23(1,2,3, c=10) # pass
a23(1,2,3, c=10, <warning descr="Duplicate argument">a=1</warning>) # fail
a23(c=10, a=1) # pass
a23(c=10, <warning descr="Cannot appear past keyword arguments or *arg or **kwarg">1</warning><warning descr="Parameter 'a' unfilled">)</warning> # fail
a23(<warning descr="More arguments than positional parameters left">*args</warning>, a=1) # fail
a23(*args, c=1) # pass
@@ -0,0 +1,5 @@
def f20(a, (b, c)):
pass
f20(1, [2, 3]) # ok
f20(1, (2, 3, <warning descr="Unexpected argument">4</warning>)) # fail: 4 is unexpected
@@ -47,11 +47,6 @@ public class PythonInspectionsTest extends PyLightFixtureTestCase {
doTest(getTestName(false), inspection);
}
public void testPyArgumentListInspection() {
LocalInspectionTool inspection = new PyArgumentListInspection();
doTest(getTestName(false), inspection);
}
public void testPyMethodParametersInspection() {
LocalInspectionTool inspection = new PyMethodParametersInspection();
doTest(getTestName(false), inspection);
@@ -62,11 +57,6 @@ public class PythonInspectionsTest extends PyLightFixtureTestCase {
doTest(getTestName(false), inspection);
}
public void testPyArgumentListInspection3K() {
LocalInspectionTool inspection = new PyArgumentListInspection();
doTestWithPy3k(getTestName(false), inspection);
}
public void testPyRedeclarationInspection() {
LocalInspectionTool inspection = new PyRedeclarationInspection();
doTest(getTestName(false), inspection);
@@ -1,11 +1,57 @@
package com.jetbrains.python.inspections;
import com.jetbrains.python.fixtures.PyLightFixtureTestCase;
import com.jetbrains.python.psi.LanguageLevel;
import com.jetbrains.python.psi.impl.PythonLanguageLevelPusher;
/**
* @author yole
*/
public class PyArgumentListInspectionTest extends PyLightFixtureTestCase {
public void testBadarglist() {
doTest();
}
public void testKwargsMapToNothing() {
doTest();
}
public void testDecorators() {
doTest();
}
public void testTupleVsLiteralList() {
doTest();
}
public void testInheritedInit() { // PY-312
doTest();
}
public void testBadDecorator() { // PY-428
doTest();
}
public void testImplicitResolveResult() {
doTest();
}
public void testCallingClassDefinition() {
doTest();
}
public void testPy1133() {
doTest();
}
public void testPy2005() {
doTest();
}
public void testPy1268() {
doTest();
}
public void testInstanceMethodAsLambda() {
doTest();
}
@@ -33,6 +79,16 @@ public class PyArgumentListInspectionTest extends PyLightFixtureTestCase {
public void testFunctionStoredInInstance() { // PY-3623
doTest();
}
public void testPy3k() {
PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), LanguageLevel.PYTHON30);
try {
doTest();
}
finally {
PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), null);
}
}
private void doTest() {
myFixture.configureByFile("inspections/PyArgumentListInspection/" + getTestName(true) + ".py");