Fix broken test. Properly initialize inspection tools in PyQuickFixTest and PyInspectionTestCase

Use InspectionProfileImpl.INIT_INSPECTIONS flag for this purpose.
Additionally I've added test case about black list in
PyShadowingBuiltinsInspection that works similarly to affected
PyUnresolvedReferencesInspection.
This commit is contained in:
Mikhail Golubev
2015-03-12 15:48:10 +03:00
parent 9b8dc4933c
commit 02a9f21844
5 changed files with 52 additions and 4 deletions

View File

@@ -16,13 +16,16 @@
package com.jetbrains.python.inspections.quickfix;
import com.intellij.codeInsight.intention.LowPriorityAction;
import com.intellij.codeInspection.*;
import com.intellij.codeInspection.InspectionProfile;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ModifiableModel;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.QualifiedName;
import com.intellij.util.Consumer;
import com.jetbrains.python.inspections.unresolvedReference.PyUnresolvedReferencesInspection;
import com.intellij.psi.util.QualifiedName;
import org.jetbrains.annotations.NotNull;
/**
@@ -69,6 +72,7 @@ public class AddIgnoredIdentifierQuickFix implements LocalQuickFix, LowPriorityA
if (myIgnoreAllAttributes) {
name += END_WILDCARD;
}
assert inspection != null;
if (!inspection.ignoredIdentifiers.contains(name)) {
inspection.ignoredIdentifiers.add(name);
}

View File

@@ -0,0 +1,6 @@
def o<caret>pen():
pass
# Sentinel definition to make sure that other warnings are still present
def <weak_warning descr="Shadows built-in name 'input'">input</weak_warning>():
pass

View File

@@ -6,4 +6,7 @@ print(a.f<caret>oo)
def func(c):
x = A() if c else None
return x.foo
return x.foo
# Sentinel reference to make sure that other warnings are still present
<error descr="Unresolved reference 'UNRESOLVED'">UNRESOLVED</error>

View File

@@ -16,6 +16,7 @@
package com.jetbrains.python;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.testFramework.TestDataFile;
import com.intellij.testFramework.TestDataPath;
import com.jetbrains.python.codeInsight.PyCodeInsightSettings;
@@ -33,6 +34,18 @@ import org.jetbrains.annotations.NonNls;
@TestDataPath("$CONTENT_ROOT/../testData/inspections/")
public class PyQuickFixTest extends PyTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
InspectionProfileImpl.INIT_INSPECTIONS = true;
}
@Override
protected void tearDown() throws Exception {
InspectionProfileImpl.INIT_INSPECTIONS = false;
super.tearDown();
}
public void testAddImport() {
doInspectionTest(new String[] { "AddImport.py", "ImportTarget.py" }, PyUnresolvedReferencesInspection.class, "Import 'ImportTarget'", true, true);
}
@@ -46,7 +59,7 @@ public class PyQuickFixTest extends PyTestCase {
}
public void testImportFromModule() {
doInspectionTest(new String[] { "importFromModule/foo/bar.py", "importFromModule/foo/baz.py", "importFromModule/foo/__init__.py" },
doInspectionTest(new String[]{"importFromModule/foo/bar.py", "importFromModule/foo/baz.py", "importFromModule/foo/__init__.py"},
PyUnresolvedReferencesInspection.class, "Import 'importFromModule.foo.baz'", true, true);
}
@@ -470,6 +483,15 @@ public class PyQuickFixTest extends PyTestCase {
myFixture.checkResultByFile(graftBeforeExt(fileName, "_after"));
}
public void testIgnoreShadowingBuiltins() {
myFixture.configureByFile("IgnoreShadowingBuiltins.py");
myFixture.enableInspections(PyShadowingBuiltinsInspection.class);
final IntentionAction intentionAction = myFixture.getAvailableIntention("Ignore shadowed built-in name \"open\"");
assertNotNull(intentionAction);
myFixture.launchAction(intentionAction);
myFixture.checkHighlighting(true, false, true);
}
// PY-8991
public void testRemoveUnicodePrefixFromGluedStringNodesWithSlash() {
runWithLanguageLevel(LanguageLevel.PYTHON32, new Runnable() {

View File

@@ -1,5 +1,6 @@
package com.jetbrains.python.fixtures;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.jetbrains.python.inspections.PyInspection;
import org.jetbrains.annotations.NotNull;
@@ -20,6 +21,18 @@ public abstract class PyInspectionTestCase extends PyTestCase {
@NotNull
protected abstract Class<? extends PyInspection> getInspectionClass();
@Override
protected void setUp() throws Exception {
super.setUp();
InspectionProfileImpl.INIT_INSPECTIONS = true;
}
@Override
protected void tearDown() throws Exception {
InspectionProfileImpl.INIT_INSPECTIONS = false;
super.tearDown();
}
/**
* Launches test. To be called by test author
*/