Exemplo n.º 1
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.IsTrue(execute.Result.IsSuccessful);
     Assert.AreEqual(replWindow.Output, "'__main__'\r\n");
     replWindow.ClearScreen();
 }
Exemplo n.º 2
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.IsTrue(execute.Result.IsSuccessful);

            OverloadDoc[] sigs = null;
            for (int retries = 0; retries < 5 && sigs == null; retries += 1) {
                sigs = replEval.GetSignatureDocumentation("Array[int]");
            }
            Assert.IsNotNull(sigs, "GetSignatureDocumentation timed out");
            Assert.AreEqual(sigs.Length, 1);
            Assert.AreEqual("Array[int](: int)\r\n", sigs[0].Documentation);
        }
Exemplo n.º 3
0
 private static bool EvaluatorUsesThisInterpreter(PythonReplEvaluator pyEval, IPythonInterpreterFactory interpreter) {
     return pyEval != null &&
         pyEval.Interpreter != null &&
         pyEval.Interpreter.Id == interpreter.Id &&
         pyEval.Interpreter.Configuration.Version == interpreter.Configuration.Version;
 }
Exemplo n.º 4
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.IsTrue(execute.Result.IsSuccessful);
 }
Exemplo n.º 5
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.IsTrue(execute.Result.IsSuccessful);
     replWindow.ClearScreen();
 }
Exemplo n.º 6
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.IsTrue(execute.Result.IsSuccessful);
            }

            replWindow.ClearScreen();
            var finalExecute = replEval.ExecuteText("42");
            finalExecute.Wait();
            Assert.IsTrue(finalExecute.Result.IsSuccessful);
            Assert.AreEqual(replWindow.Output, "42\r\n");
        }
Exemplo n.º 7
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.IsTrue(execute.Result.IsSuccessful);
            replWindow.ClearScreen();

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

            Assert.IsTrue(execute.Result.IsSuccessful);

            execute = replEval.ExecuteText("t = Task.Factory.StartNew(func1)");
            execute.Wait();
            Assert.IsTrue(execute.Result.IsSuccessful);

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

                MemberResult[] names = null;
                for (int retries = 0; retries < 5 && names == null; retries += 1) {
                    names = replEval.GetMemberNames("t");
                }
                Assert.IsNotNull(names, "GetMemberNames call timed out");
                foreach (var name in names) {
                    Debug.WriteLine(name.Name);
                }
            }
        }
Exemplo n.º 8
0
        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.IsTrue(execute.Result.IsSuccessful);
            replWindow.ClearScreen();

            execute = replEval.ExecuteText("sys.gettrace()");
            execute.Wait();
            AssertUtil.AreEqual(
                new Regex(@"\<bound method Thread.trace_func of \<Thread.+\>\>"),
                replWindow.Output
            );
            replWindow.ClearScreen();
        }
Exemplo n.º 9
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.º 10
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.IsTrue(execute.Result.IsSuccessful);
            replWindow.ClearScreen();

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

            Assert.IsTrue(execute.Result.IsSuccessful);

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

            Assert.IsTrue(execute.Result.IsSuccessful);

            Assert.AreEqual(replWindow.Output, "42");
        }
Exemplo n.º 11
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 + ">"
            );
        }
Exemplo n.º 12
0
        private static void TestOutput(MockReplWindow window, PythonReplEvaluator evaluator, string code, bool success, Action<bool> afterExecute, bool equalOutput, int timeout = 3000, params string[] expectedOutput) {
            window.ClearScreen();

            bool completed = false;
            var task = evaluator.ExecuteText(code).ContinueWith(completedTask => {
                Assert.AreEqual(success, completedTask.Result.IsSuccessful);

                var output = success ? window.Output : window.Error;
                if (equalOutput) {
                    if (output.Length == 0) {
                        Assert.IsTrue(expectedOutput.Length == 0);
                    } else {
                        // don't count ending \n as new empty line
                        output = output.Replace("\r\n", "\n");
                        if (output[output.Length - 1] == '\n') {
                            output = output.Remove(output.Length - 1, 1);
                        }

                        var lines = output.Split('\n');
                        if (lines.Length != expectedOutput.Length) {
                            for (int i = 0; i < lines.Length; i++) {
                                Console.WriteLine("{0}: {1}", i, lines[i].ToString());
                            }
                        }

                        Assert.AreEqual(lines.Length, expectedOutput.Length);
                        for (int i = 0; i < expectedOutput.Length; i++) {
                            Assert.AreEqual(lines[i], expectedOutput[i]);
                        }
                    }
                } else {
                    foreach (var line in expectedOutput) {
                        Assert.IsTrue(output.Contains(line), string.Format("'{0}' does not contain '{1}'", output, line));
                    }
                }

                completed = true;
            });

            if (afterExecute != null) {
                afterExecute(completed);
            }

            try {
                task.Wait(timeout);
            } catch (AggregateException ex) {
                if (ex.InnerException != null) {
                    throw ex.InnerException;
                }
                throw;
            }

            if (!completed) {
                Assert.Fail(string.Format("command didn't complete in {0} seconds", timeout / 1000.0));
            }
        }
Exemplo n.º 13
0
 private static void TestOutput(MockReplWindow window, PythonReplEvaluator evaluator, string code, bool success, params string[] expectedOutput) {
     TestOutput(window, evaluator, code, success, null, true, 3000, expectedOutput);
 }
Exemplo n.º 14
0
 private static PythonReplEvaluator MakeEvaluator() {
     var python = PythonPaths.Python27 ?? PythonPaths.Python27_x64 ?? PythonPaths.Python26 ?? PythonPaths.Python26_x64;
     python.AssertInstalled();
     var provider = new SimpleFactoryProvider(python.InterpreterPath, python.InterpreterPath);
     var eval = new PythonReplEvaluator(provider.GetInterpreterFactories().First(), PythonToolsTestUtilities.CreateMockServiceProvider(), new ReplTestReplOptions());
     Assert.IsTrue(eval._Initialize(new MockReplWindow(eval)).Result.IsSuccessful);
     return eval;
 }
Exemplo n.º 15
0
 private static IEnumerable<string> GetActiveInputs(IWpfTextView activeView, PythonReplEvaluator eval) {
     return eval.JoinCode(activeView.Selection.SelectedSpans.SelectMany(s => eval.SplitCode(s.GetText())));
 }