PyLightFixtureTestCase introduced and used for PythonInspectionsTest; CodeInsightTestFixture is capable of testing inspections

This commit is contained in:
Dmitry Jemerov
2009-07-28 22:18:31 +04:00
parent 8218bb7d91
commit 484e7aefd8
2 changed files with 81 additions and 15 deletions
@@ -1,52 +1,51 @@
package com.jetbrains.python;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.testFramework.InspectionTestCase;
import com.jetbrains.python.fixtures.PyLightFixtureTestCase;
import com.jetbrains.python.inspections.*;
/**
* @author yole
*/
public class PythonInspectionsTest extends InspectionTestCase {
@Override
protected Sdk getTestProjectJdk() {
return PythonMockSdk.findOrCreate();
}
public void testReturnValueFromInit() throws Exception {
public class PythonInspectionsTest extends PyLightFixtureTestCase {
public void testReturnValueFromInit() throws Throwable {
final JythonManager manager = JythonManager.getInstance();
manager.execScriptFromResource("inspections/inspections.py"); // could be moved to setUp() if more jython-based inspections existed
doTest(getTestName(true), PythonPyInspectionToolProvider.getInstance().createLocalInspectionTool("ReturnValueFromInitInspection"));
}
public void testPyMethodFirstArgAssignmentInspection() throws Exception {
private void doTest(String testName, LocalInspectionTool localInspectionTool) throws Throwable {
myFixture.testInspection(testName, new LocalInspectionToolWrapper(localInspectionTool));
}
public void testPyMethodFirstArgAssignmentInspection() throws Throwable {
LocalInspectionTool inspection = new PyMethodFirstArgAssignmentInspection();
doTest(getTestName(false), inspection);
}
public void testPyUnreachableCodeInspection() throws Exception {
public void testPyUnreachableCodeInspection() throws Throwable {
LocalInspectionTool inspection = new PyUnreachableCodeInspection();
doTest(getTestName(false), inspection);
}
public void testPyUnresolvedReferencesInspection() throws Exception {
public void testPyUnresolvedReferencesInspection() throws Throwable {
LocalInspectionTool inspection = new PyUnresolvedReferencesInspection();
doTest(getTestName(false), inspection);
}
public void testPyArgumentListInspection() throws Exception {
public void testPyArgumentListInspection() throws Throwable {
LocalInspectionTool inspection = new PyArgumentListInspection();
doTest(getTestName(false), inspection);
}
public void testPyRedeclarationInspection() throws Exception {
public void testPyRedeclarationInspection() throws Throwable {
LocalInspectionTool inspection = new PyRedeclarationInspection();
doTest(getTestName(false), inspection);
}
public void testPyStringFormatInspection() throws Exception {
public void testPyStringFormatInspection() throws Throwable {
LocalInspectionTool inspection = new PyStringFormatInspection();
doTest(getTestName(false), inspection);
}
@@ -0,0 +1,67 @@
package com.jetbrains.python.fixtures;
import com.intellij.openapi.module.EmptyModuleType;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.UsefulTestCase;
import com.intellij.testFramework.fixtures.CodeInsightTestFixture;
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture;
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory;
import com.intellij.testFramework.fixtures.TestFixtureBuilder;
import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl;
import com.jetbrains.python.PythonMockSdk;
import org.jetbrains.annotations.Nullable;
/**
* @author yole
*/
public class PyLightFixtureTestCase extends UsefulTestCase {
private static final PyLightProjectDescriptor ourPyDescriptor = new PyLightProjectDescriptor();
protected CodeInsightTestFixture myFixture;
@Override
protected void setUp() throws Exception {
super.setUp();
IdeaTestFixtureFactory factory = IdeaTestFixtureFactory.getFixtureFactory();
TestFixtureBuilder<IdeaProjectTestFixture> fixtureBuilder = factory.createLightFixtureBuilder(getProjectDescriptor());
final IdeaProjectTestFixture fixture = fixtureBuilder.getFixture();
myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(fixture, new LightTempDirTestFixtureImpl());
myFixture.setUp();
myFixture.setTestDataPath(getTestDataPath());
}
protected String getTestDataPath() {
return null;
}
@Override
protected void tearDown() throws Exception {
myFixture.tearDown();
myFixture = null;
super.tearDown();
}
@Nullable
protected LightProjectDescriptor getProjectDescriptor() {
return ourPyDescriptor;
}
private static class PyLightProjectDescriptor implements LightProjectDescriptor {
public ModuleType getModuleType() {
return EmptyModuleType.getInstance();
}
public Sdk getSdk() {
return PythonMockSdk.findOrCreate();
}
public void configureModule(Module module, ModifiableRootModel model) {
}
}
}