Пример #1
0
        public ReplWindowProxy ExecuteInInteractive(Project project, ReplWindowProxySettings settings = null)
        {
            // Prepare makes sure that IPython mode is disabled, and that the REPL is reset and cleared
            var window = ReplWindowProxy.Prepare(this, settings, project.Name);

            OpenSolutionExplorer().SelectProject(project);
            ExecuteCommand("Python.ExecuteInInteractive");
            return(window);
        }
Пример #2
0
 public SessionHolder(T session, ReplWindowProxy owner)
 {
     Assert.IsNotNull(session);
     Session = session;
     _owner  = owner;
 }
Пример #3
0
        public static ReplWindowProxy Prepare(
            PythonVisualStudioApp app,
            ReplWindowProxySettings settings,
            string projectName,
            string workspaceName,
            bool useIPython = false
            )
        {
            settings.AssertValid();

            ReplWindowProxy result = null;

            try {
                result = OpenInteractive(app, settings, projectName, workspaceName, useIPython ? IPythonBackend : StandardBackend);
                app    = null;

                for (int retries = 10; retries > 0; --retries)
                {
                    result.Reset();
                    result.ClearScreen();
                    result.ClearInput();

                    try {
                        var task = result.ExecuteText("print('READY')");
                        Assert.IsTrue(task.Wait(useIPython ? 30000 : 15000), "ReplWindow did not initialize in time");
                        if (!task.Result.IsSuccessful)
                        {
                            continue;
                        }
                    } catch (TaskCanceledException) {
                        continue;
                    }


                    if (useIPython)
                    {
                        // The longer we wait, the better are the chances of detecting this error
                        // This seems long enough to detect it when running locally
                        Thread.Sleep(500);

                        if (result.TextView.TextBuffer.CurrentSnapshot.Lines
                            .Any(l => l.GetText().Contains("Error using selected REPL back-end"))
                            )
                        {
                            Assert.Inconclusive("IPython is not available");
                        }

                        // In IPython mode, a help header appears at startup,
                        // but the output order is inconsistent, so we can't WaitForTextEnd
                        // (sometimes READY appears before help, sometimes after)
                        result.WaitForAnyLineContainsTextInternal("READY");
                        result.WaitForReadyForInput(TimeSpan.FromSeconds(5));
                    }
                    else
                    {
                        result.WaitForTextEnd("READY", ">");
                    }

                    result.ClearScreen();
                    return(result);
                }
                Assert.Fail("ReplWindow did not initialize");
                return(null);
            } finally {
                if (app != null)
                {
                    app.Dispose();
                }
            }
        }