Search in sources :

Example 1 with ManagerInfoToUpdate

use of org.python.pydev.ast.codecompletion.revisited.ManagerInfoToUpdate 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));
    }
}
Also used : ArrayList(java.util.ArrayList) DataAndImageTreeNode(org.python.pydev.shared_core.structure.DataAndImageTreeNode) IInterpreterManager(org.python.pydev.core.IInterpreterManager) SyncSystemModulesManager(org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManager) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) DataAndImageTreeNode(org.python.pydev.shared_core.structure.DataAndImageTreeNode) TreeNode(org.python.pydev.shared_core.structure.TreeNode) Collection(java.util.Collection) InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) HashMap(java.util.HashMap) Map(java.util.Map) ManagerInfoToUpdate(org.python.pydev.ast.codecompletion.revisited.ManagerInfoToUpdate)

Example 2 with ManagerInfoToUpdate

use of org.python.pydev.ast.codecompletion.revisited.ManagerInfoToUpdate 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());
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) ArrayList(java.util.ArrayList) DataAndImageTreeNode(org.python.pydev.shared_core.structure.DataAndImageTreeNode) IInterpreterManager(org.python.pydev.core.IInterpreterManager) SyncSystemModulesManager(org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManager) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) DataAndImageTreeNode(org.python.pydev.shared_core.structure.DataAndImageTreeNode) TreeNode(org.python.pydev.shared_core.structure.TreeNode) Collection(java.util.Collection) InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) HashMap(java.util.HashMap) Map(java.util.Map) PythonpathChange(org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManager.PythonpathChange) ManagerInfoToUpdate(org.python.pydev.ast.codecompletion.revisited.ManagerInfoToUpdate) HashSet(java.util.HashSet)

Example 3 with ManagerInfoToUpdate

use of org.python.pydev.ast.codecompletion.revisited.ManagerInfoToUpdate 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());
    }
}
Also used : ArrayList(java.util.ArrayList) DataAndImageTreeNode(org.python.pydev.shared_core.structure.DataAndImageTreeNode) IInterpreterManager(org.python.pydev.core.IInterpreterManager) SyncSystemModulesManager(org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManager) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) IInfo(org.python.pydev.core.IInfo) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) DataAndImageTreeNode(org.python.pydev.shared_core.structure.DataAndImageTreeNode) TreeNode(org.python.pydev.shared_core.structure.TreeNode) Collection(java.util.Collection) InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) HashMap(java.util.HashMap) Map(java.util.Map) ManagerInfoToUpdate(org.python.pydev.ast.codecompletion.revisited.ManagerInfoToUpdate)

Aggregations

AdditionalSystemInterpreterInfo (com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 ManagerInfoToUpdate (org.python.pydev.ast.codecompletion.revisited.ManagerInfoToUpdate)3 SyncSystemModulesManager (org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManager)3 InterpreterInfo (org.python.pydev.ast.interpreter_managers.InterpreterInfo)3 IInterpreterInfo (org.python.pydev.core.IInterpreterInfo)3 IInterpreterManager (org.python.pydev.core.IInterpreterManager)3 DataAndImageTreeNode (org.python.pydev.shared_core.structure.DataAndImageTreeNode)3 TreeNode (org.python.pydev.shared_core.structure.TreeNode)3 HashSet (java.util.HashSet)1 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1 PythonpathChange (org.python.pydev.ast.codecompletion.revisited.SyncSystemModulesManager.PythonpathChange)1 IInfo (org.python.pydev.core.IInfo)1