Exemplo n.º 1
0
        public void GenericMethodCompletions()
        {
            // http://pytools.codeplex.com/workitem/661
            var fact       = IronPythonInterpreter;
            var replEval   = new PythonReplEvaluator(fact, PythonToolsTestUtilities.CreateMockServiceProvider(), new ReplTestReplOptions());
            var replWindow = new MockReplWindow(replEval);

            replEval.Initialize(replWindow).Wait();
            var execute = replEval.ExecuteText("from System.Threading.Tasks import Task");

            execute.Wait();
            Assert.AreEqual(execute.Result, ExecutionResult.Success);
            replWindow.ClearScreen();

            execute = replEval.ExecuteText("def func1(): print 'hello world'\r\n\r\n");
            execute.Wait();
            replWindow.ClearScreen();

            Assert.AreEqual(execute.Result, ExecutionResult.Success);

            execute = replEval.ExecuteText("t = Task.Factory.StartNew(func1)");
            execute.Wait();
            Assert.AreEqual(execute.Result, ExecutionResult.Success);

            using (var analyzer = new VsProjectAnalyzer(PythonToolsTestUtilities.CreateMockServiceProvider(), fact, new[] { fact })) {
                replWindow.TextView.TextBuffer.Properties.AddProperty(typeof(VsProjectAnalyzer), analyzer);

                var names = replEval.GetMemberNames("t");
                foreach (var name in names)
                {
                    Debug.WriteLine(name.Name);
                }
            }
        }
Exemplo n.º 2
0
        public void AttachSupportMultiThreaded()
        {
            // http://pytools.codeplex.com/workitem/663
            var replEval   = new PythonReplEvaluator(IronPythonInterpreter, PythonToolsTestUtilities.CreateMockServiceProvider(), new ReplTestReplOptions());
            var replWindow = new MockReplWindow(replEval);

            replEval.Initialize(replWindow).Wait();
            var code = new[] {
                "import threading",
                "def sayHello():\r\n    pass",
                "t1 = threading.Thread(target=sayHello)",
                "t1.start()",
                "t2 = threading.Thread(target=sayHello)",
                "t2.start()"
            };

            foreach (var line in code)
            {
                var execute = replEval.ExecuteText(line);
                execute.Wait();
                Assert.AreEqual(execute.Result, ExecutionResult.Success);
            }

            replWindow.ClearScreen();
            var finalExecute = replEval.ExecuteText("42");

            finalExecute.Wait();
            Assert.AreEqual(finalExecute.Result, ExecutionResult.Success);
            Assert.AreEqual(replWindow.Output, "42\r\n");
        }
Exemplo n.º 3
0
        public void ConsoleWriteLineTest()
        {
            // http://pytools.codeplex.com/workitem/649
            var replEval   = new PythonReplEvaluator(IronPythonInterpreter, PythonToolsTestUtilities.CreateMockServiceProvider(), new ReplTestReplOptions());
            var replWindow = new MockReplWindow(replEval);

            replEval.Initialize(replWindow).Wait();
            var execute = replEval.ExecuteText("import System");

            execute.Wait();
            Assert.AreEqual(execute.Result, ExecutionResult.Success);
            replWindow.ClearScreen();

            execute = replEval.ExecuteText("System.Console.WriteLine(42)");
            execute.Wait();
            Assert.AreEqual(replWindow.Output, "42\r\n");
            replWindow.ClearScreen();

            Assert.AreEqual(execute.Result, ExecutionResult.Success);

            execute = replEval.ExecuteText("System.Console.Write(42)");
            execute.Wait();

            Assert.AreEqual(execute.Result, ExecutionResult.Success);

            Assert.AreEqual(replWindow.Output, "42");
        }
Exemplo n.º 4
0
        public void BadInterpreterPath()
        {
            // http://pytools.codeplex.com/workitem/662

            var emptyFact = InterpreterFactoryCreator.CreateInterpreterFactory(
                new InterpreterFactoryCreationOptions()
            {
                Description     = "Test Interpreter",
                InterpreterPath = "C:\\Does\\Not\\Exist\\Some\\Interpreter.exe"
            }
                );
            var replEval   = new PythonReplEvaluator(emptyFact, PythonToolsTestUtilities.CreateMockServiceProvider(), new ReplTestReplOptions());
            var replWindow = new MockReplWindow(replEval);

            replEval.Initialize(replWindow);
            var          execute   = replEval.ExecuteText("42");
            var          errorText = replWindow.Error;
            const string expected  =
                "The interactive window could not be started because the associated Python environment could not be found.\r\n" +
                "If this version of Python has recently been uninstalled, you can close this window.\r\n" +
                "Current interactive window is disconnected.";

            if (!errorText.Contains(expected))
            {
                Assert.Fail(string.Format(
                                "Did not find:\n{0}\n\nin:\n{1}",
                                expected,
                                errorText
                                ));
            }
        }
Exemplo n.º 5
0
        public void IronPythonCommentInput()
        {
            // http://pytools.codeplex.com/workitem/649
            var replEval   = new PythonReplEvaluator(IronPythonInterpreter, PythonToolsTestUtilities.CreateMockServiceProvider(), new ReplTestReplOptions());
            var replWindow = new MockReplWindow(replEval);

            replEval.Initialize(replWindow).Wait();
            var execute = replEval.ExecuteText("#fob\n1+2");

            execute.Wait();
            Assert.AreEqual(execute.Result, ExecutionResult.Success);
        }
Exemplo n.º 6
0
        public void CommentFollowedByBlankLine()
        {
            // http://pytools.codeplex.com/workitem/659
            var replEval   = new PythonReplEvaluator(IronPythonInterpreter, PythonToolsTestUtilities.CreateMockServiceProvider(), new ReplTestReplOptions());
            var replWindow = new MockReplWindow(replEval);

            replEval.Initialize(replWindow).Wait();
            var execute = replEval.ExecuteText("# fob\r\n\r\n    \r\n\t\t\r\na = 42");

            execute.Wait();
            Assert.AreEqual(execute.Result, ExecutionResult.Success);
            replWindow.ClearScreen();
        }
Exemplo n.º 7
0
        public void IronPythonModuleName()
        {
            var replEval   = new PythonReplEvaluator(IronPythonInterpreter, PythonToolsTestUtilities.CreateMockServiceProvider(), new ReplTestReplOptions());
            var replWindow = new MockReplWindow(replEval);

            replEval.Initialize(replWindow).Wait();
            replWindow.ClearScreen();
            var execute = replEval.ExecuteText("__name__");

            execute.Wait();
            Assert.AreEqual(execute.Result, ExecutionResult.Success);
            Assert.AreEqual(replWindow.Output, "'__main__'\r\n");
            replWindow.ClearScreen();
        }
Exemplo n.º 8
0
        public void IronPythonSignatures()
        {
            var replEval   = new PythonReplEvaluator(IronPythonInterpreter, PythonToolsTestUtilities.CreateMockServiceProvider(), new ReplTestReplOptions());
            var replWindow = new MockReplWindow(replEval);

            replEval.Initialize(replWindow).Wait();
            var execute = replEval.ExecuteText("from System import Array");

            execute.Wait();
            Assert.AreEqual(execute.Result, ExecutionResult.Success);

            var sigs = replEval.GetSignatureDocumentation("Array[int]");

            Assert.AreEqual(sigs.Length, 1);
            Assert.AreEqual("Array[int](: int)\r\n", sigs[0].Documentation);
        }
        public void NoTraceFunction()
        {
            // http://pytools.codeplex.com/workitem/662
            var replEval   = new PythonReplEvaluator(IronPythonInterpreter, PythonToolsTestUtilities.CreateMockServiceProvider(), new ReplTestReplOptions());
            var replWindow = new MockReplWindow(replEval);

            replEval.Initialize(replWindow).Wait();
            var execute = replEval.ExecuteText("import sys");

            execute.Wait();
            Assert.AreEqual(execute.Result, ExecutionResult.Success);
            replWindow.ClearScreen();

            execute = replEval.ExecuteText("sys.gettrace()");
            execute.Wait();
            Assert.AreEqual(replWindow.Output, "");
            replWindow.ClearScreen();
        }
Exemplo n.º 10
0
        public void NoInterpreterPath()
        {
            // http://pytools.codeplex.com/workitem/662

            var emptyFact = InterpreterFactoryCreator.CreateInterpreterFactory(
                new InterpreterFactoryCreationOptions()
            {
                Description = "Test Interpreter"
            }
                );
            var replEval   = new PythonReplEvaluator(emptyFact, PythonToolsTestUtilities.CreateMockServiceProvider(), new ReplTestReplOptions());
            var replWindow = new MockReplWindow(replEval);

            replEval.Initialize(replWindow);
            var execute = replEval.ExecuteText("42");

            Console.WriteLine(replWindow.Error);
            Assert.IsTrue(
                replWindow.Error.Contains("Test Interpreter cannot be started"),
                "Expected: <Test Interpreter cannot be started>\r\nActual: <" + replWindow.Error + ">"
                );
        }