Ejemplo n.º 1
0
        public void ReadLineReturnsNullWhenConsoleDisposed()
        {
            PythonConsole console = new PythonConsole(new MockTextEditor(), null);

            console.Dispose();
            Assert.IsNull(console.ReadLine(0));
        }
        public void SetUpFixture()
        {
            MockTextEditor textEditor = new MockTextEditor();

            using (pythonConsole = new PythonConsole(textEditor, null)) {
                textEditor.RaiseKeyPressEvent('a');
                textEditor.RaiseKeyPressEvent('=');
                textEditor.RaiseKeyPressEvent('1');
                lineAvailableBeforeFirstEnterKey = pythonConsole.IsLineAvailable;
                textEditor.RaiseDialogKeyPressEvent(Keys.Enter);
                lineAvailableAfterFirstEnterKey = pythonConsole.IsLineAvailable;

                textEditor.RaiseKeyPressEvent('b');
                textEditor.RaiseKeyPressEvent('=');
                textEditor.RaiseKeyPressEvent('2');
                textEditor.RaiseDialogKeyPressEvent(Keys.Enter);

                Thread t = new Thread(ReadLinesOnSeparateThread);
                t.Start();

                int sleepInterval = 20;
                int currentWait   = 0;
                int maxWait       = 2000;

                while (line2 == null && currentWait < maxWait)
                {
                    Thread.Sleep(sleepInterval);
                    currentWait += sleepInterval;
                }

                lineAvailableAtEnd = pythonConsole.IsLineAvailable;
            }
        }
Ejemplo n.º 3
0
        public void Init()
        {
            mockTextEditor = new MockTextEditor();
            pythonConsole  = new PythonConsole(mockTextEditor, null);

            autoIndentSize = initialAutoIndentSize;
            Thread thread = new Thread(ReadLineFromConsoleOnDifferentThread);

            thread.Start();

            int sleepInterval = 10;
            int maxWait       = 2000;
            int currentWait   = 0;

            while (mockTextEditor.Text.Length < autoIndentSize && currentWait < maxWait)
            {
                Thread.Sleep(sleepInterval);
                currentWait += sleepInterval;
            }

            raiseKeyPressEvent       = mockTextEditor.RaiseKeyPressEvent('a');
            raiseDialogKeyPressEvent = mockTextEditor.RaiseDialogKeyPressEvent(Keys.Enter);

            currentWait = 0;
            while (mockTextEditor.Text.Length < autoIndentSize + 2 && currentWait < maxWait)
            {
                Thread.Sleep(10);
                currentWait += sleepInterval;
            }
            thread.Join(2000);
        }
Ejemplo n.º 4
0
    public void AbortExecution()
    {
        if (CurrentGraph == null || CurrentGraphNodes == null)
        {
            return;
        }

        PythonConsole.AbortCurrentProcess();
    }
Ejemplo n.º 5
0
        public void HostDisposesPythonConsole()
        {
            DerivedPythonConsoleHost host    = new DerivedPythonConsoleHost(new MockTextEditor());
            PythonConsole            console = host.CallCreateConsole(null, null, null) as PythonConsole;

            host.Dispose();

            Assert.IsNull(console.ReadLine(0));
        }
        public void SetUpFixture()
        {
            textEditor = new MockTextEditor();
            console    = new PythonConsole(textEditor, null);
            console.WriteLine(prompt, Style.Prompt);

            textEditor.RaiseKeyPressEvents("__builtins__");
            showCompletionWindowCalledBeforeDotTypedIn = textEditor.IsShowCompletionWindowCalled;
            textEditor.RaiseKeyPressEvent('.');
        }
Ejemplo n.º 7
0
        public void Run()
        {
            _server = new NamedPipeServerStream(Name);

            //TODO: dynamically program and start python client
            PythonConsole console = new PythonConsole(Name);

            console.Start();

            LogService.LogInfo("Waiting for connection...");
            _server.WaitForConnection();

            LogService.LogInfo("Client Connected");

            _reader = new BinaryReader(_server);
            _writer = new BinaryWriter(_server);

            while (true)
            {
                LogService.LogInfo("Enter code to execute:");
                var input = Console.ReadLine();
                try
                {
                    WriteMessage(input);

                    var result = ReadMessage();

                    if (result == null)
                    {
                        LogService.LogError("Invalid response, terminating...");
                        return;
                    }

                    if (result.MessageType.Equals(EMessageType.ERROR))
                    {
                        LogService.LogError(((TextMessage)result).Text);
                    }
                    else
                    {
                        var resultMessage = (ResultMessage)result;
                        var value         = resultMessage.GetValue();
                        LogService.LogInfo($"{value} ({resultMessage.Type})");
                    }
                }
                catch (IOException)
                {
                    _server.Close();
                    LogService.LogError("Connection lost, reconnecting.");
                    Run();
                    return;
                }
            }
        }
        public void Init()
        {
            textEditor    = new MockTextEditor();
            pythonConsole = new PythonConsole(textEditor, null);
            pythonConsole.Write(prompt, Style.Prompt);

            textEditor.RaiseKeyPressEvent('a');
            textEditor.RaiseDialogKeyPressEvent(Keys.Enter);
            pythonConsole.Write(prompt, Style.Prompt);
            textEditor.RaiseKeyPressEvent('b');
            textEditor.RaiseKeyPressEvent('.');
        }
Ejemplo n.º 9
0
        public void NoTextWrittenWhenAutoIndentSizeIsZero()
        {
            MockTextEditor textEditor = new MockTextEditor();
            PythonConsole  console    = new PythonConsole(textEditor, null);

            textEditor.RaiseKeyPressEvent('a');
            textEditor.RaiseDialogKeyPressEvent(Keys.Enter);

            textEditor.IsWriteCalled = false;
            console.ReadLine(0);
            Assert.IsFalse(textEditor.IsWriteCalled);
        }
Ejemplo n.º 10
0
        public static bool CompileAndRun(Graph graph)
        {
            if (!initialised)
            {
                VSLogger.LogError("VScriptEngine not initialised");
                return(false);
            }

            try
            {
                string graph_path = Compiler.main.Compile(graph);
                VSLogger.Log("===Executing '" + graph.display_name + "'===");
                PythonConsole.RunGraph(graph_path, input_function);
                VSLogger.Log("===Finished execution===");
                return(true);
            }
            catch (Exception e)
            {
                VSLogger.LogError(e.Message + "\n" + e.StackTrace);
                VSLogger.Log("===Aborting execution===");
                return(false);
            }
        }
 public void Init()
 {
     textEditor = new MockTextEditor();
     console    = new PythonConsole(textEditor, null);
     console.Write(prompt, Style.Prompt);
 }
 public void Init()
 {
     mockTextEditor      = new MockTextEditor();
     mockTextEditor.Text = String.Empty;
     pythonConsole       = new PythonConsole(mockTextEditor, null);
 }
 public void Init()
 {
     textEditor    = new MockTextEditor();
     pythonConsole = new PythonConsole(textEditor, null);
 }
Ejemplo n.º 14
0
 internal static void CallInitializeScript(PythonConsole console)
 {
 }
Ejemplo n.º 15
0
 internal static void ConfigureVariables(PythonConsole console)
 {
 }
Ejemplo n.º 16
0
        public override Declarations GetDeclarations(IVsTextView view, int line, int col, TokenInfo info, ParseReason reason)
        {
            // Check that the text view is not null.
            if (null == view)
            {
                throw new ArgumentNullException("view");
            }

            // In order to get the correct text for this line we have to figure out if this line
            // contains part of the read-only region of the buffer because this region is not
            // supposed to be used (it is the output of the engine).
            // Use the function exposed by the console window to get the text of the line
            // without the part inside the read-only region.
            string lineText = PythonConsole.TextOfLine(line, col, true);

            if (null == lineText)
            {
                // there is no text to parse, so there is no delaration to return.
                // Return an empty Declarations object.
                return(new MethodDeclarations());
            }

            // Get the text buffer.
            IVsTextLines buffer;

            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                view.GetBuffer(out buffer));

            // Get the scanner from the language service.
            IScanner scanner = Language.GetScanner(buffer);

            scanner.SetSource(lineText, 0);

            // Now use the scanner to parse this line and build the list of the tokens.
            List <TokenInfo> tokens       = new List <TokenInfo>();
            TokenInfo        lastToken    = null;
            TokenInfo        currentToken = new TokenInfo();
            int state = 0;

            while (scanner.ScanTokenAndProvideInfoAboutIt(currentToken, ref state))
            {
                if ((null != lastToken) && (currentToken.StartIndex > lastToken.EndIndex + 1))
                {
                    tokens.Clear();
                }
                tokens.Add(currentToken);
                lastToken    = currentToken;
                currentToken = new TokenInfo();
            }

            // Now that we have the tokens we can use them to find the text to pass to the
            // IronPython engine to evaluate the expression.
            if (0 == tokens.Count)
            {
                // If the list of tokens is empty, then return an emty set of declarations.
                return(new MethodDeclarations());
            }

            // Check if the last token is the one that generated the parse request.
            if (tokens[tokens.Count - 1].Trigger == TokenTriggers.None)
            {
                tokens.RemoveAt(tokens.Count - 1);
                if (0 == tokens.Count)
                {
                    return(new MethodDeclarations());
                }
            }

            // Remove the token that generated the request
            if (tokens[tokens.Count - 1].Trigger != TokenTriggers.None)
            {
                tokens.RemoveAt(tokens.Count - 1);
                if (0 == tokens.Count)
                {
                    return(new MethodDeclarations());
                }
            }

            // Now build the string to pass to the engine.
            int    startIndex    = tokens[0].StartIndex;
            int    len           = tokens[tokens.Count - 1].EndIndex - startIndex + 1;
            string engineCommand = string.Format(
                System.Globalization.CultureInfo.InvariantCulture,
                "dir({0})",
                lineText.Substring(startIndex, len));

            MethodDeclarations declarations = new MethodDeclarations();

            try
            {
                IEnumerable members = Engine.Evaluate(engineCommand) as IEnumerable;
                if (null != members)
                {
                    foreach (string member in members)
                    {
                        declarations.AddMethod(member);
                    }
                }
            }
            catch (Exception)
            {
                // Do nothing
            }
            return(declarations);
        }
Ejemplo n.º 17
0
        public void PythonConsoleImplementsIDisposable()
        {
            PythonConsole console = new PythonConsole(new MockTextEditor(), null);

            Assert.IsNotNull(console as IDisposable);
        }