use of com.jetbrains.python.psi.PyFile in project intellij-community by JetBrains.
the class MoveFromFutureImportQuickFix method applyFix.
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement problemElement = descriptor.getPsiElement();
final PsiFile psiFile = problemElement.getContainingFile();
if (psiFile instanceof PyFile) {
AddImportHelper.addFromImportStatement(psiFile, (PyFromImportStatement) problemElement, AddImportHelper.ImportPriority.FUTURE, null);
problemElement.delete();
}
}
use of com.jetbrains.python.psi.PyFile in project intellij-community by JetBrains.
the class PyDeprecationTest method testFunctionStub.
public void testFunctionStub() {
myFixture.configureByFile("deprecation/functionStub.py");
PyFile file = (PyFile) myFixture.getFile();
assertEquals("commands.getstatus() is deprecated", file.findTopLevelFunction("getstatus").getDeprecationMessage());
PlatformTestUtil.tryGcSoftlyReachableObjects();
assertNotParsed(file);
assertEquals("commands.getstatus() is deprecated", file.findTopLevelFunction("getstatus").getDeprecationMessage());
assertNotParsed(file);
}
use of com.jetbrains.python.psi.PyFile in project intellij-community by JetBrains.
the class PyDeprecationTest method testFunction.
public void testFunction() {
myFixture.configureByText(PythonFileType.INSTANCE, "def getstatus(file):\n" + " \"\"\"Return output of \"ls -ld <file>\" in a string.\"\"\"\n" + " import warnings\n" + " warnings.warn(\"commands.getstatus() is deprecated\", DeprecationWarning, 2)\n" + " return getoutput('ls -ld' + mkarg(file))");
PyFunction getstatus = ((PyFile) myFixture.getFile()).findTopLevelFunction("getstatus");
assertEquals("commands.getstatus() is deprecated", getstatus.getDeprecationMessage());
}
use of com.jetbrains.python.psi.PyFile in project intellij-community by JetBrains.
the class PyBlockEvaluatorTest method doEvaluate.
private PyBlockEvaluator doEvaluate(String text, boolean skipEvaluatingCollectionItems) {
PyBlockEvaluator eval = new PyBlockEvaluator();
if (skipEvaluatingCollectionItems) {
eval.setEvaluateCollectionItems(false);
}
PyFile file = (PyFile) PsiFileFactory.getInstance(myFixture.getProject()).createFileFromText("a.py", PythonFileType.INSTANCE, text);
eval.evaluate(file);
return eval;
}
use of com.jetbrains.python.psi.PyFile in project intellij-community by JetBrains.
the class PyBlockEvaluatorTest method testFunction.
public void testFunction() {
PyBlockEvaluator eval = new PyBlockEvaluator();
PyFile file = (PyFile) PsiFileFactory.getInstance(myFixture.getProject()).createFileFromText("a.py", PythonFileType.INSTANCE, "def foo(): return 'a'");
PyFunction foo = file.findTopLevelFunction("foo");
eval.evaluate(foo);
assertEquals("a", eval.getReturnValue());
}
Aggregations