mock SDK for Python inspections test

This commit is contained in:
Dmitry Jemerov
2009-07-27 19:54:14 +04:00
parent da7f6cff06
commit d7d5ecd796
4 changed files with 71 additions and 5 deletions
+14
View File
@@ -0,0 +1,14 @@
@echo off
rem This file was generated by the Jython installer
rem Created on Wed Mar 05 12:52:03 MSK 2008 by yole
set ARGS=
:loop
if [%1] == [] goto end
set ARGS=%ARGS% %1
shift
goto loop
:end
"C:\Program Files (x86)\Java\jre1.6.0_04\bin\java.exe" -Dpython.home="C:\jython2.2.1" -classpath "C:\jython2.2.1\jython.jar;%CLASSPATH%" org.python.util.jython %ARGS%
@@ -239,9 +239,16 @@ public class PythonSdkType extends SdkType {
}
protected SdkModificator setupSdkPathsUnderProgress(final Sdk sdk, ProgressIndicator indicator) {
protected SdkModificator setupSdkPathsUnderProgress(final Sdk sdk, @Nullable ProgressIndicator indicator) {
final SdkModificator sdkModificator = sdk.getSdkModificator();
String sdk_path = sdk.getHomePath();
setupSdkPaths(sdkModificator, indicator);
return sdkModificator;
//sdkModificator.commitChanges() must happen outside, and probably in a different thread.
}
public static void setupSdkPaths(SdkModificator sdkModificator, ProgressIndicator indicator) {
String sdk_path = sdkModificator.getHomePath();
String bin_path = getInterpreterPath(sdk_path);
@NonNls final String stubs_path =
PathManager.getSystemPath() + File.separator + "python_stubs" + File.separator + sdk_path.hashCode() + File.separator;
@@ -280,9 +287,6 @@ public class PythonSdkType extends SdkType {
sdkModificator.addRoot(LocalFileSystem.getInstance().refreshAndFindFileByPath(stubs_path), OrderRootType.SOURCES);
}
generateBinaryStubs(sdk_path, stubs_path, indicator);
return sdkModificator;
//sdkModificator.commitChanges() must happen outside, and probably in a different thread.
}
private static List<String> getSysPath(String sdk_path, String bin_path) {
@@ -2,6 +2,7 @@ package com.jetbrains.python;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.testFramework.InspectionTestCase;
import com.jetbrains.python.inspections.*;
@@ -9,6 +10,11 @@ import com.jetbrains.python.inspections.*;
* @author yole
*/
public class PythonInspectionsTest extends InspectionTestCase {
@Override
protected Sdk getTestProjectJdk() {
return PythonMockSdk.findOrCreate();
}
public void testReturnValueFromInit() throws Exception {
final JythonManager manager = JythonManager.getInstance();
manager.execScriptFromResource("inspections/inspections.py"); // could be moved to setUp() if more jython-based inspections existed
@@ -0,0 +1,42 @@
package com.jetbrains.python;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.projectRoots.ProjectJdkTable;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.SdkModificator;
import com.intellij.openapi.projectRoots.SdkType;
import com.intellij.openapi.projectRoots.impl.ProjectJdkImpl;
import com.jetbrains.python.sdk.PythonSdkType;
import org.jetbrains.annotations.NonNls;
import java.io.File;
import java.util.List;
/**
* @author yole
*/
public class PythonMockSdk {
@NonNls private static final String MOCK_SDK_NAME = "Mock Jython SDK";
public static Sdk findOrCreate() {
final List<Sdk> sdkList = ProjectJdkTable.getInstance().getSdksOfType(PythonSdkType.getInstance());
for (Sdk sdk : sdkList) {
if (sdk.getName().equals(MOCK_SDK_NAME)) {
return sdk;
}
}
return create();
}
public static Sdk create() {
String sdkHome = new File(PathManager.getHomePath(), "plugins/python/lib").getPath();
SdkType sdkType = PythonSdkType.getInstance();
final Sdk sdk = new ProjectJdkImpl(MOCK_SDK_NAME, sdkType);
final SdkModificator sdkModificator = sdk.getSdkModificator();
sdkModificator.setHomePath(sdkHome);
PythonSdkType.setupSdkPaths(sdkModificator, null);
sdkModificator.commitChanges();
return sdk;
}
}