Fix test for packing generalization introduced in python 3.5: remove unreal test cases, fix false positives for packed reference and call expressions

This commit is contained in:
Valentina Kiryushkina
2017-05-15 14:37:57 +03:00
parent f1d8ea5c82
commit 0ab6f65d37
9 changed files with 50 additions and 16 deletions
@@ -235,10 +235,17 @@ public class PySubstitutionChunkReference extends PsiReferenceBase<PyStringLiter
PyExpression underStarExpr = PyPsiUtils.flattenParens(expression.getExpression());
if (underStarExpr != null) {
if (underStarExpr instanceof PyDictLiteralExpression) {
return getElementFromDictLiteral((PyDictLiteralExpression)underStarExpr, index);
Ref<PyExpression> expr = getElementFromDictLiteral((PyDictLiteralExpression)underStarExpr, index);
allKeysForSure = expr != null;
if (expr != null && !expr.isNull()) return expr;
}
else if (underStarExpr instanceof PyCallExpression) {
return getElementFromCallExpression((PyCallExpression)underStarExpr, index.toString());
Ref<PyExpression> expr = getElementFromCallExpression((PyCallExpression)underStarExpr, index.toString());
allKeysForSure = expr != null;
if (expr != null && !expr.isNull()) return expr;
}
else {
allKeysForSure = false;
}
}
}
@@ -462,10 +469,17 @@ public class PySubstitutionChunkReference extends PsiReferenceBase<PyStringLiter
PyExpression underStarExpr = PyPsiUtils.flattenParens(expr.getExpression());
if (underStarExpr != null) {
if (underStarExpr instanceof PyDictLiteralExpression) {
return getElementFromDictLiteral(underStarExpr, mappingKey);
Ref<PyExpression> element = getElementFromDictLiteral(underStarExpr, mappingKey);
allKeysForSure = element != null;
if (element != null && !element.isNull()) return element;
}
else if (underStarExpr instanceof PyCallExpression) {
return getElementFromCallExpression((PyCallExpression)underStarExpr, mappingKey);
Ref<PyExpression> element = getElementFromCallExpression((PyCallExpression)underStarExpr, mappingKey);
allKeysForSure = element != null;
if (element != null && !element.isNull()) return element;
}
else {
allKeysForSure = false;
}
}
}
@@ -1,2 +0,0 @@
"{d[a]}".format(d={"b": 1, **dict(a=2)})
<warning descr="Too few arguments for format string">"{d[c]}"</warning>.format(d={"b": 1, **dict(a=2)})
@@ -1,2 +0,0 @@
"{d[1]}".format(d={2: a, **{1: b}})
<warning descr="Too few arguments for format string">"{d[3]}"</warning>.format(d={2: a, **{1: b}})
@@ -0,0 +1,3 @@
old_dict = {1: "b"}
"{d[2]}".format(d={**old_dict, 2: "a"})
"{d[1]}".format(d={**old_dict, 2: "a"})
@@ -1,2 +1,2 @@
"{b}".format(**{"a": 1, **{"b": 2}})
<warning descr="Key 'c' has no corresponding argument">"{c}"</warning>.format(**{"a": 1, **{"b": 2}})
"{b}".format(**{"a": 1, **dict(b=2)})
<warning descr="Key 'c' has no corresponding argument">"{c}"</warning>.format(**{"a": 1, **dict(b=2)})
@@ -1,2 +1,3 @@
"{b}".format(**{"a": 1, **{"b":2}})
<warning descr="Key 'c' has no corresponding argument">"{c}"</warning>.format(**{"a": 1, **{"b":2}})
"{c}".format(**{**{"b":2}, "a": 1, **{"c":2}})
<warning descr="Key 'd' has no corresponding argument">"{d}"</warning>.format(**{**{"b":2}, "a": 1, **{"c":2}})
@@ -0,0 +1,8 @@
list = [3, 4]
"{3}".format(*[1, 2, *list])
"{4}".format(*[1, 2, *list])
"{1}".format(*[1, 2, *list])
"{3}".format(*[*list, 1, 2])
"{4}".format(*[*list, 1, 2])
"{1}".format(*[*list, 1, 2])
@@ -0,0 +1,8 @@
tuple = (3, 4)
"{3}".format(*[1, 2, *tuple])
"{4}".format(*[1, 2, *tuple])
"{1}".format(*[1, 2, *tuple])
"{3}".format(*[*tuple, 1, 2])
"{4}".format(*[*tuple, 1, 2])
"{1}".format(*[*tuple, 1, 2])
@@ -37,11 +37,7 @@ public class Py3StringFormatInspectionTest extends PyTestCase {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest);
}
public void testIndexElementWithPackedDictLiteralInsideDictLiteralArg() {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest);
}
public void testIndexElementWithPackedDictCallInsideDictLiteralArg() {
public void testIndexElementWithPackedReferenceExpr() {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest);
}
@@ -69,6 +65,14 @@ public class Py3StringFormatInspectionTest extends PyTestCase {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest);
}
public void testPackedRefInsideList() {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest);
}
public void testPackedRefInsideTuple() {
runWithLanguageLevel(LanguageLevel.PYTHON35, this::doTest);
}
// PY-20599
public void testPy3kAsciiFormatSpecifier() {
runWithLanguageLevel(LanguageLevel.PYTHON35, () -> doTest());