fixed failed tests.

This commit is contained in:
Ekaterina Tuzova
2011-01-23 15:47:43 +03:00
parent 2161e2fc49
commit 03f04c515e
9 changed files with 22 additions and 47 deletions

View File

@@ -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__"));
}
}
}
}
}
}
}

View File

@@ -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();
}

View File

@@ -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

View File

@@ -0,0 +1 @@
print(<warning descr="Python versions 3.0 do not support <>, use != instead.">a<caret> <> b</warning>)

View File

@@ -1 +0,0 @@
print(<caret>a <> b)

View File

@@ -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);
}

View File

@@ -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() {

View File

@@ -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);
}