use of org.python.pydev.ast.interpreter_managers.InterpreterInfo in project Pydev by fabioz.
the class SyncSystemModulesManagerTest method testUpdateAndApply.
public void testUpdateAndApply() throws Exception {
setupEnv();
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);
// Ok, the interpreter should be synchronized with the pythonpath which is currently set.
// Now, check a different scenario: create a new path and add it to the interpreter pythonpath.
// In this situation, the sync manager should ask the user if that path should actually be added
// to this interpreter.
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(libDir2.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(5, interpreterInfo.getModulesManager().getSize(false));
}
}
use of org.python.pydev.ast.interpreter_managers.InterpreterInfo in project Pydev by fabioz.
the class SyncSystemModulesManagerTest method checkUpdateStructures.
private void checkUpdateStructures(SyncSystemModulesManager synchManager, final DataAndImageTreeNode root, ManagerInfoToUpdate managerToNameToInfo) {
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());
// Still the same!
final InterpreterInfo info = new InterpreterInfo("2.6", TestDependent.PYTHON2_EXE, pythonpath);
return info;
}
});
Tuple<IInterpreterManager, IInterpreterInfo>[] managerAndInfos = managerToNameToInfo.getManagerAndInfos();
int found = managerAndInfos.length;
assertEquals(found, 1);
}
use of org.python.pydev.ast.interpreter_managers.InterpreterInfo in project Pydev by fabioz.
the class SyncSystemModulesManagerTest method testSaveUserChoicesAfterSelection.
public void testSaveUserChoicesAfterSelection() throws Exception {
setupEnv(false);
IEclipsePreferences preferences = createPreferenceStore();
SyncSystemModulesManager synchManager = new SyncSystemModulesManager();
final DataAndImageTreeNode root = new DataAndImageTreeNode(null, null, null);
Map<IInterpreterManager, Map<String, IInterpreterInfo>> managerToNameToInfo = InterpreterManagersAPI.getInterpreterManagerToInterpreterNameToInfo();
synchManager.updateStructures(null, root, new ManagerInfoToUpdate(managerToNameToInfo), new SyncSystemModulesManager.CreateInterpreterInfoCallback() {
@Override
public IInterpreterInfo createInterpreterInfo(IInterpreterManager manager, String executable, IProgressMonitor monitor) {
Collection<String> pythonpath = new ArrayList<>();
pythonpath.add(libDir.toString());
pythonpath.add(libDir2.toString());
pythonpath.add(libDir3.toString());
pythonpath.add(libZipFile.toString());
final InterpreterInfo info = new InterpreterInfo("2.6", TestDependent.PYTHON2_EXE, pythonpath);
return info;
}
});
assertTrue(root.hasChildren());
List<TreeNode> selectedElements = new ArrayList<>();
TreeNode interpreterNode = (TreeNode) root.getChildren().get(0);
selectedElements.add(interpreterNode);
List<TreeNode> children = interpreterNode.getChildren();
for (TreeNode<PythonpathChange> treeNode : children) {
if (treeNode.getData().path.equals(libDir2.toString())) {
selectedElements.add(treeNode);
}
}
synchManager.saveUnselected(root, selectedElements, preferences);
// Check that we ignored libDir3 and libZipFile
String key = SyncSystemModulesManager.createKeyForInfo((IInterpreterInfo) ((TreeNode) root.getChildren().get(0)).getData());
String entry = preferences.get(key, "");
List<String> entries = StringUtils.split(entry, "|||");
assertEquals(2, entries.size());
HashSet<String> entriesSet = new HashSet<>(entries);
assertEquals(new HashSet(entries), new HashSet(Arrays.asList(libDir3.toString(), libZipFile.toString())));
// Check that only libDir2 is initially selected.
List<TreeNode> initialSelection = synchManager.createInitialSelectionForDialogConsideringPreviouslyIgnored(root, preferences);
assertEquals(2, initialSelection.size());
TreeNode treeNode = initialSelection.get(0);
TreeNode treeNode1 = initialSelection.get(1);
TreeNode interpreterInfoNode;
TreeNode pythonpathNode;
if (treeNode.getData() instanceof IInterpreterInfo) {
interpreterNode = treeNode;
pythonpathNode = treeNode1;
} else {
interpreterNode = treeNode1;
pythonpathNode = treeNode;
}
assertEquals(((PythonpathChange) pythonpathNode.getData()).path, libDir2.toString());
}
use of org.python.pydev.ast.interpreter_managers.InterpreterInfo in project Pydev by fabioz.
the class IronPythonCodeCompletionTestsBase method setInterpreterManager.
@Override
protected void setInterpreterManager(String path) {
IronpythonInterpreterManager interpreterManager = new IronpythonInterpreterManager(this.getPreferences());
InterpreterInfo info = (InterpreterInfo) interpreterManager.createInterpreterInfo(TestDependent.IRONPYTHON_EXE, new NullProgressMonitor(), false);
TestDependent.IRONPYTHON_EXE = info.executableOrJar;
if (path != null) {
info = new InterpreterInfo(info.getVersion(), info.executableOrJar, PythonPathHelper.parsePythonPathFromStr(path, new ArrayList<String>()));
}
interpreterManager.setInfos(new IInterpreterInfo[] { info }, null, null);
InterpreterManagersAPI.setIronpythonInterpreterManager(interpreterManager);
}
use of org.python.pydev.ast.interpreter_managers.InterpreterInfo in project Pydev by fabioz.
the class CodeCompletionTestsBase method afterRestorSystemPythonPath.
/**
* @param info the information for the system manager that we just restored
*/
protected void afterRestorSystemPythonPath(InterpreterInfo info) {
// has to be restored for the project, as we just restored the system pythonpath
nature = null;
// ok, the system manager must be there
assertTrue(info.getModulesManager().getSize(true) > 0);
// and it must be registered as the pydev interpreter manager
IInterpreterManager iMan2 = getInterpreterManager();
InterpreterInfo info2;
try {
info2 = (InterpreterInfo) iMan2.getDefaultInterpreterInfo(false);
} catch (MisconfigurationException e) {
throw new RuntimeException(e);
}
assertTrue(info2 == info);
// does it have the loaded modules?
assertTrue(info2.getModulesManager().getSize(true) > 0);
assertTrue(info2.getModulesManager().getBuiltins().length > 0);
}
Aggregations