use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class SyncSystemModulesManagerTest method checkSynchronize.
private void checkSynchronize(SyncSystemModulesManager synchManager, final DataAndImageTreeNode root, ManagerInfoToUpdate managerToNameToInfo) {
// Ok, all is Ok in the PYTHONPATH, so, check if something changed inside the interpreter info
// and not on the PYTHONPATH.
assertFalse(root.hasChildren());
InterpreterInfoBuilder builder = new InterpreterInfoBuilder();
synchManager.synchronizeManagerToNameToInfoPythonpath(null, managerToNameToInfo, builder);
Tuple<IInterpreterManager, IInterpreterInfo>[] managerAndInfos = managerToNameToInfo.getManagerAndInfos();
for (Tuple<IInterpreterManager, IInterpreterInfo> tuple : managerAndInfos) {
InterpreterInfo interpreterInfo = (InterpreterInfo) tuple.o2;
assertEquals(3, interpreterInfo.getModulesManager().getSize(false));
}
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class SyncSystemModulesManagerTest method testUpdateWhenEggIsAdded.
public void testUpdateWhenEggIsAdded() throws Exception {
setupEnv(true);
SyncSystemModulesManager synchManager = new SyncSystemModulesManager();
final DataAndImageTreeNode root = new DataAndImageTreeNode(null, null, null);
Map<IInterpreterManager, Map<String, IInterpreterInfo>> managerToNameToInfoMap = InterpreterManagersAPI.getInterpreterManagerToInterpreterNameToInfo();
ManagerInfoToUpdate managerToNameToInfo = new ManagerInfoToUpdate(managerToNameToInfoMap);
checkUpdateStructures(synchManager, root, managerToNameToInfo);
checkSynchronize(synchManager, root, managerToNameToInfo);
root.clear();
managerToNameToInfo = new ManagerInfoToUpdate(InterpreterManagersAPI.getInterpreterManagerToInterpreterNameToInfo());
synchManager.updateStructures(null, root, managerToNameToInfo, new SyncSystemModulesManager.CreateInterpreterInfoCallback() {
@Override
public IInterpreterInfo createInterpreterInfo(IInterpreterManager manager, String executable, IProgressMonitor monitor) {
Collection<String> pythonpath = new ArrayList<String>();
pythonpath.add(libDir.toString());
pythonpath.add(libZipFile.toString());
final InterpreterInfo info = new InterpreterInfo("2.6", TestDependent.PYTHON2_EXE, pythonpath);
return info;
}
});
assertTrue(root.hasChildren());
List<TreeNode> selectElements = new ArrayList<>();
selectElements.addAll(root.flattenChildren());
synchManager.applySelectedChangesToInterpreterInfosPythonpath(root, selectElements, null);
List<IInterpreterInfo> allInterpreterInfos = InterpreterManagersAPI.getAllInterpreterInfos();
for (IInterpreterInfo interpreterInfo : allInterpreterInfos) {
assertEquals(4, interpreterInfo.getModulesManager().getSize(false));
AdditionalSystemInterpreterInfo additionalInfo = (AdditionalSystemInterpreterInfo) AdditionalSystemInterpreterInfo.getAdditionalSystemInfo(interpreterInfo.getModulesManager().getInterpreterManager(), interpreterInfo.getExecutableOrJar());
Collection<IInfo> allTokens = additionalInfo.getAllTokens();
assertEquals(4, additionalInfo.getAllTokens().size());
}
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class AbstractWorkbenchTestCase method createPythonInterpreterManager.
/**
* Creates the python interpreter manager with the default jython jar location.
*/
protected static void createPythonInterpreterManager(NullProgressMonitor monitor) {
IInterpreterManager iMan = InterpreterManagersAPI.getPythonInterpreterManager(true);
IInterpreterInfo interpreterInfo = iMan.createInterpreterInfo(TestDependent.PYTHON2_EXE, monitor, false);
iMan.setInfos(new IInterpreterInfo[] { interpreterInfo }, null, null);
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class AbstractWorkbenchTestCase method createJythonInterpreterManager.
/**
* Creates the jython interpreter manager with the default jython jar location.
*/
protected static void createJythonInterpreterManager(NullProgressMonitor monitor) {
IInterpreterManager iMan = InterpreterManagersAPI.getJythonInterpreterManager(true);
IInterpreterInfo interpreterInfo = iMan.createInterpreterInfo(TestDependent.JYTHON_JAR_LOCATION, monitor, false);
iMan.setInfos(new IInterpreterInfo[] { interpreterInfo }, null, null);
}
use of org.python.pydev.core.IInterpreterManager in project Pydev by fabioz.
the class AdditionalInterpreterInfoTest method testForcedBuiltinsInAdditionalInfo.
// Not working with lucene searches (test must be fixed).
//
// public void testCompleteIndex() throws Exception {
// String doc = "class Test:\n" +
// " class Test2:\n" +
// " def mmm(self):\n" +
// " a = mmm1\n"
// +
// " print mmm1";
// File tempFileAt = FileUtils.getTempFileAt(baseDir, "data_temporary_file_on_additional_interpreter_info_test",
// ".py");
// FileUtils.writeStrToFile(doc, tempFileAt);
// try {
// SourceModule module = AbstractModule.createModuleFromDoc("test", tempFileAt, new Document(
// doc), nature, true);
// info.addAstInfo(module.getAst(), new ModulesKey("test", tempFileAt), false);
//
// List<ModulesKey> modulesWithTokensStartingWith = null;
//
// modulesWithTokensStartingWith = info.getModulesWithToken("mmm", null);
// assertEquals(1, modulesWithTokensStartingWith.size());
//
// modulesWithTokensStartingWith = info.getModulesWithToken("mmm1", null);
// assertEquals(1, modulesWithTokensStartingWith.size());
//
// modulesWithTokensStartingWith = info.getModulesWithToken("mmm4", null);
// assertEquals(0, modulesWithTokensStartingWith.size());
//
// synchronized (this) {
// wait(1000);
// }
//
// doc = "new contents";
// FileUtils.writeStrToFile(doc, tempFileAt);
//
// info.removeInfoFromModule("test", true);
// info.addAstInfo(new ModulesKey("test", tempFileAt), true);
// modulesWithTokensStartingWith = info.getModulesWithToken("mmm", null);
// assertEquals(0, modulesWithTokensStartingWith.size());
//
// modulesWithTokensStartingWith = info.getModulesWithToken("contents", null);
// assertEquals(1, modulesWithTokensStartingWith.size());
// } finally {
// tempFileAt.delete();
// }
// }
@SuppressWarnings("unchecked")
public void testForcedBuiltinsInAdditionalInfo() throws Exception {
IInterpreterManager interpreterManager = getInterpreterManager();
String defaultInterpreter = interpreterManager.getDefaultInterpreterInfo(false).getExecutableOrJar();
AbstractAdditionalDependencyInfo additionalSystemInfo = AdditionalSystemInterpreterInfo.getAdditionalSystemInfo(interpreterManager, defaultInterpreter);
checkItertoolsToken(additionalSystemInfo, false);
InterpreterInfo defaultInterpreterInfo = (InterpreterInfo) interpreterManager.getDefaultInterpreterInfo(false);
HashSet<String> set = new HashSet<>(Arrays.asList(defaultInterpreterInfo.getBuiltins()));
assertTrue(set.contains("itertools"));
// Now, update the information to contain the builtin tokens!
new InterpreterInfoBuilder().syncInfoToPythonPath(new NullProgressMonitor(), defaultInterpreterInfo);
checkItertoolsToken(additionalSystemInfo, true);
// Remove and re-update to check if it's fixed.
additionalSystemInfo.removeInfoFromModule("itertools", false);
checkItertoolsToken(additionalSystemInfo, false);
new InterpreterInfoBuilder().syncInfoToPythonPath(new NullProgressMonitor(), defaultInterpreterInfo);
checkItertoolsToken(additionalSystemInfo, true);
int indexSize = additionalSystemInfo.completeIndex.keys().size();
AdditionalSystemInterpreterInfo newAdditionalInfo = new AdditionalSystemInterpreterInfo(interpreterManager, defaultInterpreter);
AdditionalSystemInterpreterInfo.setAdditionalSystemInfo(interpreterManager, defaultInterpreter, newAdditionalInfo);
newAdditionalInfo.load();
assertEquals(indexSize, newAdditionalInfo.completeIndex.keys().size());
final List<ModulesKey> added = new ArrayList<>();
final List<ModulesKey> removed = new ArrayList<>();
ICallbackListener listener = new ICallbackListener() {
@Override
public Object call(Object obj) {
Tuple t = (Tuple) obj;
added.addAll((List<ModulesKey>) t.o1);
removed.addAll((List<ModulesKey>) t.o2);
return null;
}
};
AbstractAdditionalDependencyInfo.modulesAddedAndRemoved.registerListener(listener);
try {
new InterpreterInfoBuilder().syncInfoToPythonPath(new NullProgressMonitor(), defaultInterpreterInfo, newAdditionalInfo);
} finally {
AbstractAdditionalDependencyInfo.modulesAddedAndRemoved.unregisterListener(listener);
}
if (added.size() > 0) {
throw new AssertionError("Expected no modules to be added as we just loaded from a clean save. Found:\n" + StringUtils.join("\n", added));
}
if (removed.size() > 0) {
throw new AssertionError("Expected no modules to be removed as we just loaded from a clean save. Found:\n" + StringUtils.join("\n", removed));
}
checkItertoolsToken(newAdditionalInfo, true);
}
Aggregations