Search in sources :

Example 6 with PythonInterpreterManager

use of org.python.pydev.ast.interpreter_managers.PythonInterpreterManager in project Pydev by fabioz.

the class InterpreterInfoBuilderTest method testInterpreterInfoBuilder.

public void testInterpreterInfoBuilder() throws Exception {
    Collection<String> pythonpath = new ArrayList<String>();
    pythonpath.add(libDir.toString());
    final InterpreterInfo info = new InterpreterInfo("2.6", TestDependent.PYTHON2_EXE, pythonpath);
    IEclipsePreferences preferences = new InMemoryEclipsePreferences();
    final PythonInterpreterManager manager = new PythonInterpreterManager(preferences);
    InterpreterManagersAPI.setPythonInterpreterManager(manager);
    manager.setInfos(new IInterpreterInfo[] { info }, null, null);
    final AdditionalSystemInterpreterInfo additionalInfo = new AdditionalSystemInterpreterInfo(manager, info.getExecutableOrJar());
    AdditionalSystemInterpreterInfo.setAdditionalSystemInfo(manager, info.getExecutableOrJar(), additionalInfo);
    // Don't load it (otherwise it'll get the 'proper' info).
    // AdditionalSystemInterpreterInfo.loadAdditionalSystemInfo(manager, info.getExecutableOrJar());
    final ISystemModulesManager modulesManager = info.getModulesManager();
    assertEquals(0, modulesManager.getSize(false));
    assertEquals(0, additionalInfo.getAllTokens().size());
    InterpreterInfoBuilder builder = new InterpreterInfoBuilder();
    builder.syncInfoToPythonPath(null, info);
    int size = modulesManager.getSize(false);
    if (size != 3) {
        fail("Expected size = 3, found: " + size);
    }
    try {
        AbstractAdditionalDependencyInfo additionalSystemInfo = AdditionalSystemInterpreterInfo.getAdditionalSystemInfo(manager, manager.getInterpreterInfos()[0].getExecutableOrJar(), true);
        if (additionalInfo != additionalSystemInfo) {
            throw new RuntimeException("Expecting it to be the same instance.");
        }
    } catch (MisconfigurationException e) {
        throw new RuntimeException(e);
    }
    Collection<IInfo> allTokens = additionalInfo.getAllTokens();
    size = allTokens.size();
    if (size != 3) {
        FastStringBuffer buf = new FastStringBuffer();
        for (IInfo i : allTokens) {
            buf.append(i.toString());
        }
        fail("Expected size = 3, found: " + size + "\nTokens: " + buf);
    }
}
Also used : FastStringBuffer(org.python.pydev.shared_core.string.FastStringBuffer) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) MisconfigurationException(org.python.pydev.core.MisconfigurationException) PythonInterpreterManager(org.python.pydev.ast.interpreter_managers.PythonInterpreterManager) ArrayList(java.util.ArrayList) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) IInfo(org.python.pydev.core.IInfo) ISystemModulesManager(org.python.pydev.core.ISystemModulesManager) InterpreterInfo(org.python.pydev.ast.interpreter_managers.InterpreterInfo) AdditionalSystemInterpreterInfo(com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) AbstractAdditionalDependencyInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo) InMemoryEclipsePreferences(org.python.pydev.shared_core.preferences.InMemoryEclipsePreferences)

Aggregations

PythonInterpreterManager (org.python.pydev.ast.interpreter_managers.PythonInterpreterManager)6 ArrayList (java.util.ArrayList)5 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)5 InterpreterInfo (org.python.pydev.ast.interpreter_managers.InterpreterInfo)5 IInterpreterInfo (org.python.pydev.core.IInterpreterInfo)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 AdditionalSystemInterpreterInfo (com.python.pydev.analysis.additionalinfo.AdditionalSystemInterpreterInfo)2 List (java.util.List)2 JythonInterpreterManager (org.python.pydev.ast.interpreter_managers.JythonInterpreterManager)2 IInfo (org.python.pydev.core.IInfo)2 ISystemModulesManager (org.python.pydev.core.ISystemModulesManager)2 AbstractAdditionalDependencyInfo (com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo)1 Flake8Preferences (com.python.pydev.analysis.flake8.Flake8Preferences)1 MypyPreferences (com.python.pydev.analysis.mypy.MypyPreferences)1 PyLintPreferences (com.python.pydev.analysis.pylint.PyLintPreferences)1 File (java.io.File)1 HashSet (java.util.HashSet)1 MissingResourceException (java.util.MissingResourceException)1 ResourceBundle (java.util.ResourceBundle)1 Set (java.util.Set)1