mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-04 17:20:55 +07:00
fixed failed tests.
This commit is contained in:
@@ -4,7 +4,6 @@ import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -30,22 +29,22 @@ public class ReplaceBuiltinsQuickFix implements LocalQuickFix {
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
|
||||
PsiElement element = descriptor.getPsiElement();
|
||||
PyImportStatement importStatement = PsiTreeUtil.getParentOfType(element, PyImportStatement.class);
|
||||
for (PyImportElement importElement : importStatement.getImportElements()) {
|
||||
PyReferenceExpression importReference = importElement.getImportReference();
|
||||
if (importReference != null) {
|
||||
if (LanguageLevel.forFile(element.getContainingFile().getVirtualFile()).isPy3K()) {
|
||||
if ("__builtin__".equals(importReference.getName())) {
|
||||
importReference.replace(elementGenerator.createFromText(LanguageLevel.getDefault(), PyReferenceExpression.class, "builtins"));
|
||||
}
|
||||
} else {
|
||||
if ("builtins".equals(importReference.getName())) {
|
||||
importReference.replace(elementGenerator.createFromText(LanguageLevel.getDefault(), PyReferenceExpression.class, "__builtin__"));
|
||||
PsiElement importStatement = descriptor.getPsiElement();
|
||||
if (importStatement instanceof PyImportStatement) {
|
||||
for (PyImportElement importElement : ((PyImportStatement)importStatement).getImportElements()) {
|
||||
PyReferenceExpression importReference = importElement.getImportReference();
|
||||
if (importReference != null) {
|
||||
if (LanguageLevel.forFile(importStatement.getContainingFile().getVirtualFile()).isPy3K()) {
|
||||
if ("__builtin__".equals(importReference.getName())) {
|
||||
importReference.replace(elementGenerator.createFromText(LanguageLevel.getDefault(), PyReferenceExpression.class, "builtins"));
|
||||
}
|
||||
} else {
|
||||
if ("builtins".equals(importReference.getName())) {
|
||||
importReference.replace(elementGenerator.createFromText(LanguageLevel.getDefault(), PyReferenceExpression.class, "__builtin__"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.jetbrains.python.inspections;
|
||||
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.psi.*;
|
||||
@@ -34,6 +35,7 @@ public class PyCompatibilityInspection extends PyInspection {
|
||||
|
||||
public PyCompatibilityInspection () {
|
||||
super();
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) toVersion = LanguageLevel.PYTHON30.toString();
|
||||
myVersionsToProcess = new Vector<LanguageLevel>();
|
||||
updateVersionsToProcess();
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
from __future__ import with_statement
|
||||
|
||||
<warning descr="Python version 2.5 does not support dictionary comprehensions">{k: v for k, v in stuff}</warning>
|
||||
|
||||
try:
|
||||
pass
|
||||
<warning descr="This Python version does not support this syntax">except a as name:
|
||||
pass</warning>
|
||||
|
||||
class A(B):
|
||||
def foo(self):
|
||||
<warning descr="super() should have arguments in Python 2">super()</warning>
|
||||
|
||||
<warning descr="Python version 2.5 does not support set literal expressions">{1, 2}</warning>
|
||||
|
||||
<warning descr="Starred expressions are not allowed as assignment targets in Python 2">*b</warning>, c = 1, 2, 3, 4, 5
|
||||
|
||||
if <warning descr="<> is deprecated, use != instead">a <> 2</warning>:
|
||||
pass
|
||||
|
||||
(<warning descr="Python version 2.5 does not support set comprehensions">{i for i in range(3)}</warning>)
|
||||
|
||||
with A() as a, <warning descr="Python version 2.5 does not support multiple context managers">B() as b</warning>:
|
||||
pass
|
||||
1
python/testData/inspections/ReplaceNotEqOperator.py
Normal file
1
python/testData/inspections/ReplaceNotEqOperator.py
Normal file
@@ -0,0 +1 @@
|
||||
print(<warning descr="Python versions 3.0 do not support <>, use != instead.">a<caret> <> b</warning>)
|
||||
@@ -1 +0,0 @@
|
||||
print(<caret>a <> b)
|
||||
@@ -55,10 +55,6 @@ public class PyIntentionTest extends PyLightFixtureTestCase {
|
||||
doTest(PyBundle.message("INTN.convert.builtin.import"), LanguageLevel.PYTHON30);
|
||||
}
|
||||
|
||||
public void testReplaceNotEqOperator() {
|
||||
doTest(PyBundle.message("INTN.replace.noteq.operator"));
|
||||
}
|
||||
|
||||
public void testRemoveLeadingU() {
|
||||
doTest(PyBundle.message("INTN.remove.leading.u"), LanguageLevel.PYTHON30);
|
||||
}
|
||||
|
||||
@@ -209,6 +209,12 @@ public class PyQuickFixTest extends PyLightFixtureTestCase {
|
||||
doInspectionTest("UnresolvedRefCreateFunction.py", PyUnresolvedReferencesInspection.class,
|
||||
PyBundle.message("QFIX.unresolved.reference.create.function"), true, true);
|
||||
}
|
||||
|
||||
public void testReplaceNotEqOperator() {
|
||||
doInspectionTest("ReplaceNotEqOperator.py", PyCompatibilityInspection.class,
|
||||
PyBundle.message("INTN.replace.noteq.operator"), true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNls
|
||||
protected String getTestDataPath() {
|
||||
|
||||
@@ -133,10 +133,6 @@ public class PythonHighlightingTest extends PyLightFixtureTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testUnsupportedFeaturesInPython2() {
|
||||
doTest(LanguageLevel.PYTHON25, true, false);
|
||||
}
|
||||
|
||||
public void testUnsupportedFeaturesInPython3() {
|
||||
doTest(LanguageLevel.PYTHON30, true, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user