Exemplo n.º 1
0
        private void RunOne(PythonVisualStudioApp app, string filename, params SendToStep[] inputs)
        {
            // SendToInteractive.pyproj uses Python 3.5 32-bit
            var settings = ReplWindowSettings.FindSettingsForInterpreter("Python35");
            var sln      = app.CopyProjectForTest(@"TestData\SendToInteractive.sln");
            var project  = app.OpenProject(sln);
            var program  = project.ProjectItems.Item(filename);
            var window   = program.Open();

            window.Activate();

            var doc = app.GetDocument(program.Document.FullName);

            doc.MoveCaret(new SnapshotPoint(doc.TextView.TextBuffer.CurrentSnapshot, 0));

            var interactive = ReplWindowProxy.Prepare(app, settings, useIPython: false);

            interactive.ExecuteText("42").Wait();
            interactive.ClearScreen();

            WaitForText(interactive.TextView, ">>> ");

            var state = new StepState(interactive, app, doc, window);

            state.Content.Append(">>> ");

            foreach (var input in inputs)
            {
                input.Execute(state);
            }
        }
        internal virtual ReplWindowProxy Prepare(
            bool enableAttach = false,
            bool useIPython   = false,
            bool addNewLineAtEndOfFullyTypedWord = false
            )
        {
            var s = Settings;

            if (s.Version == null)
            {
                Assert.Inconclusive("Interpreter missing for " + GetType().Name);
            }

            if (enableAttach != s.EnableAttach)
            {
                s = object.ReferenceEquals(s, Settings) ? s.Clone() : s;
                s.EnableAttach = enableAttach;
            }
            if (addNewLineAtEndOfFullyTypedWord != s.AddNewLineAtEndOfFullyTypedWord)
            {
                s = object.ReferenceEquals(s, Settings) ? s.Clone() : s;
                s.AddNewLineAtEndOfFullyTypedWord = addNewLineAtEndOfFullyTypedWord;
            }
            if (useIPython)
            {
                s = object.ReferenceEquals(s, Settings) ? s.Clone() : s;
                s.PrimaryPrompt         = ">>> ";
                s.UseInterpreterPrompts = false;
            }

            return(ReplWindowProxy.Prepare(s, useIPython: useIPython));
        }
Exemplo n.º 3
0
        private void RunOne(string filename, params SendToStep[] inputs)
        {
            using (var app = new PythonVisualStudioApp()) {
                var project = app.OpenProject(@"TestData\SendToInteractive.sln");
                var program = project.ProjectItems.Item(filename);
                var window  = program.Open();

                window.Activate();

                var doc = app.GetDocument(program.Document.FullName);
                doc.MoveCaret(new SnapshotPoint(doc.TextView.TextBuffer.CurrentSnapshot, 0));

                var interactive = ReplWindowProxy.Prepare(new ReplWindowPython35Tests().Settings, false);

                interactive.ExecuteText("42").Wait();
                interactive.ClearScreen();

                WaitForText(interactive.TextView, ">>> ");

                var state = new StepState(interactive, app, doc, window);
                state.Content.Append(">>> ");

                foreach (var input in inputs)
                {
                    input.Execute(state);
                }
            }
        }
        internal virtual ReplWindowProxy Prepare(
            bool enableAttach = false,
            bool useIPython   = false,
            bool addNewLineAtEndOfFullyTypedWord = false
            )
        {
            var s = Settings;

            if (s.Version == null)
            {
                Assert.Inconclusive("Interpreter missing for " + GetType().Name);
            }

            if (enableAttach != s.EnableAttach)
            {
                s = s.Clone();
                s.EnableAttach = enableAttach;
            }
            if (addNewLineAtEndOfFullyTypedWord != s.AddNewLineAtEndOfFullyTypedWord)
            {
                s = s.Clone();
                s.AddNewLineAtEndOfFullyTypedWord = addNewLineAtEndOfFullyTypedWord;
            }

            return(ReplWindowProxy.Prepare(s, useIPython: useIPython));
        }
Exemplo n.º 5
0
 public StepState(ReplWindowProxy interactive, PythonVisualStudioApp app, EditorWindow editor, EnvDTE.Window window)
 {
     Interactive = interactive;
     App         = app;
     Editor      = editor;
     Window      = window;
     Content     = new StringBuilder();
 }
        public static ReplWindowProxy Prepare(
            ReplWindowProxySettings settings,
            bool useIPython = false
            )
        {
            settings.Version.AssertInstalled();

            var             app    = new PythonVisualStudioApp();
            ReplWindowProxy result = null;

            try {
                var wnd = OpenInteractive(app, settings, useIPython ? "IPython" : "Standard");
                result = new ReplWindowProxy(app, wnd, settings);
                app    = null;

                result.Window.Reset();
                result.ClearInput();

                for (int retries = 10; retries > 0; --retries)
                {
                    result.Window.Reset();
                    try {
                        var task = result.Window.Evaluator.ExecuteText("print('READY')");
                        Assert.IsTrue(task.Wait(useIPython ? 30000 : 10000), "ReplWindow did not initialize in time");
                        if (!task.Result.IsSuccessful)
                        {
                            continue;
                        }
                    } catch (TaskCanceledException) {
                        continue;
                    }

                    result.WaitForTextEnd("READY", ">");
                    if (result.TextView.TextBuffer.CurrentSnapshot.Lines
                        .Any(l => l.GetText().Contains("Error using selected REPL back-end")) &&
                        useIPython)
                    {
                        Assert.Inconclusive("IPython is not available");
                    }
                    result.ClearScreen();
                    result.ClearHistory();
                    return(result);
                }
                Assert.Fail("ReplWindow did not initialize");
                return(null);
            } finally {
                if (app != null)
                {
                    app.Dispose();
                }
            }
        }
Exemplo n.º 7
0
        private static void Run(PythonVisualStudioApp app, SendToStep[] inputs, ReplWindowProxySettings settings, EditorWindow doc, EnvDTE.Window window, string projectName = null, string workspaceName = null)
        {
            window.Activate();
            doc.MoveCaret(new SnapshotPoint(doc.TextView.TextBuffer.CurrentSnapshot, 0));
            app.WaitForCommandAvailable("Python.SendSelectionToInteractive", TimeSpan.FromSeconds(15));

            var interactive = ReplWindowProxy.Prepare(app, settings, projectName, workspaceName, useIPython: false);

            interactive.ExecuteText("42").Wait();
            interactive.ClearScreen();

            WaitForText(interactive.TextView, ">>> ");

            var state = new StepState(interactive, app, doc, window);

            state.Content.Append(">>> ");

            foreach (var input in inputs)
            {
                input.Execute(state);
            }
        }
Exemplo n.º 8
0
        internal static IMappingTagSpan <IntraTextAdornmentTag>[] WaitForTags(ReplWindowProxy interactive)
        {
            var aggFact    = interactive.App.ComponentModel.GetService <IViewTagAggregatorFactoryService>();
            var textView   = interactive.TextView;
            var aggregator = aggFact.CreateTagAggregator <IntraTextAdornmentTag>(textView);
            var snapshot   = textView.TextBuffer.CurrentSnapshot;

            IMappingTagSpan <IntraTextAdornmentTag>[] tags = null;
            ((UIElement)textView).Dispatcher.Invoke((Action)(() => {
                for (int i = 0; i < 100; i++)
                {
                    tags = aggregator.GetTags(new SnapshotSpan(snapshot, new Span(0, snapshot.Length))).ToArray();
                    if (tags.Length > 0)
                    {
                        break;
                    }
                    Thread.Sleep(100);
                }
            }));

            Assert.IsNotNull(tags, "Unable to find tags");
            return(tags);
        }
 public SessionHolder(T session, ReplWindowProxy owner)
 {
     Assert.IsNotNull(session);
     Session = session;
     _owner  = owner;
 }