use of com.jetbrains.python.psi.PyExpression in project intellij-community by JetBrains.
the class PyAssignmentMappingTest method testMultiple.
public void testMultiple() throws Exception {
Map<String, PsiElement> marks = loadTest();
final int TARGET_NUM = 3;
Assert.assertEquals(TARGET_NUM + 1, marks.size());
// const -> expr;
PsiElement src = marks.get("<src>").getParent();
PsiElement[] dsts = new PsiElement[TARGET_NUM];
for (int i = 0; i < TARGET_NUM; i += 1) {
// ident -> target expr
PsiElement dst = marks.get("<dst" + String.valueOf(i + 1) + ">").getParent();
Assert.assertTrue(dst instanceof PyTargetExpression);
dsts[i] = dst;
}
PyAssignmentStatement stmt = (PyAssignmentStatement) src.getParent();
List<Pair<PyExpression, PyExpression>> mapping = stmt.getTargetsToValuesMapping();
Assert.assertEquals(TARGET_NUM, mapping.size());
for (int i = 0; i < TARGET_NUM; i += 1) {
Pair<PyExpression, PyExpression> pair = mapping.get(i);
Assert.assertEquals(dsts[i], pair.getFirst());
Assert.assertEquals(src, pair.getSecond());
}
}
use of com.jetbrains.python.psi.PyExpression in project intellij-community by JetBrains.
the class PyTypeTest method testParameterFromUsages.
public void testParameterFromUsages() {
final String text = "def foo(bar):\n" + " expr = bar\n" + "def use_foo(x):\n" + " foo(x)\n" + " foo(3)\n" + " foo('bar')\n";
final PyExpression expr = parseExpr(text);
assertNotNull(expr);
doTest("Union[Union[int, str], Any]", expr, TypeEvalContext.codeCompletion(expr.getProject(), expr.getContainingFile()));
}
use of com.jetbrains.python.psi.PyExpression in project intellij-community by JetBrains.
the class PyTypingTest method doTest.
private void doTest(@NotNull String expectedType, @NotNull String text) {
myFixture.copyDirectoryToProject("typing", "");
myFixture.configureByText(PythonFileType.INSTANCE, text);
final PyExpression expr = myFixture.findElementByText("expr", PyExpression.class);
final TypeEvalContext codeAnalysis = TypeEvalContext.codeAnalysis(expr.getProject(), expr.getContainingFile());
final TypeEvalContext userInitiated = TypeEvalContext.userInitiated(expr.getProject(), expr.getContainingFile()).withTracing();
assertType(expectedType, expr, codeAnalysis, "code analysis");
assertType(expectedType, expr, userInitiated, "user initiated");
}
Aggregations