コード例 #1
0
        private string GetScriptPath(EnvironmentView view)
        {
            if (view == null)
            {
                return(null);
            }

            string path;

            lock (_cachedScriptPaths) {
                if (_cachedScriptPaths.TryGetValue(view, out path))
                {
                    return(path);
                }
            }

            try {
                path = _uiThread.Invoke(() => PythonInteractiveEvaluator.GetScriptsPath(
                                            _site,
                                            view.Description,
                                            view.Factory.Configuration,
                                            false
                                            ));
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                view.Dispatcher.BeginInvoke((Action)(() => ex.ReportUnhandledException(_site, GetType())), DispatcherPriority.ApplicationIdle);
                path = null;
            }

            lock (_cachedScriptPaths) {
                _cachedScriptPaths[view] = path;
            }
            return(path);
        }
コード例 #2
0
ファイル: ReplEvaluatorTests.cs プロジェクト: wasya2009/PTVS
        public void BadInterpreterPath()
        {
            // http://pytools.codeplex.com/workitem/662

            var replEval = new PythonInteractiveEvaluator(PythonToolsTestUtilities.CreateMockServiceProvider())
            {
                DisplayName   = "Test Interpreter",
                Configuration = new LaunchConfiguration(new VisualStudioInterpreterConfiguration("InvalidInterpreter", "Test Interpreter", pythonExePath: "C:\\Does\\Not\\Exist\\Some\\Interpreter.exe"))
            };
            var replWindow = new MockReplWindow(replEval);

            replEval._Initialize(replWindow);
            var          execute   = replEval.ExecuteText("42");
            var          errorText = replWindow.Error;
            const string expected  = "the associated Python environment could not be found.";

            if (!errorText.Contains(expected))
            {
                Assert.Fail(string.Format(
                                "Did not find:\n{0}\n\nin:\n{1}",
                                expected,
                                errorText
                                ));
            }
        }
コード例 #3
0
        private static void TestOutput(MockReplWindow window, PythonInteractiveEvaluator 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) {
                    ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
                }
                throw;
            }

            if (!completed) {
                Assert.Fail(string.Format("command didn't complete in {0} seconds", timeout / 1000.0));
            }
        }
コード例 #4
0
 private static PythonInteractiveEvaluator MakeEvaluator() {
     var python = PythonPaths.Python27_x64 ?? PythonPaths.Python27;
     python.AssertInstalled();
     var provider = new SimpleFactoryProvider(python.InterpreterPath, python.InterpreterPath);
     var eval = new PythonInteractiveEvaluator(PythonToolsTestUtilities.CreateMockServiceProvider()) {
         Configuration = new LaunchConfiguration(python.Configuration)
     };
     Assert.IsTrue(eval._Initialize(new MockReplWindow(eval)).Result.IsSuccessful);
     return eval;
 }
コード例 #5
0
        private string GetScriptPath(EnvironmentView view)
        {
            if (view == null)
            {
                return(null);
            }

            return(PythonInteractiveEvaluator.GetScriptsPath(
                       _site,
                       view.Description,
                       view.Factory.Configuration,
                       false
                       ));
        }
コード例 #6
0
        public async Task NoInterpreterPath() {
            // http://pytools.codeplex.com/workitem/662

            var replEval = new PythonInteractiveEvaluator(PythonToolsTestUtilities.CreateMockServiceProvider()) {
                DisplayName = "Test Interpreter"
            };
            var replWindow = new MockReplWindow(replEval);
            await replEval._Initialize(replWindow);
            await 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 + ">"
            );
        }
コード例 #7
0
ファイル: ReplEvaluatorTests.cs プロジェクト: wasya2009/PTVS
 private static void TestOutput(MockReplWindow window, PythonInteractiveEvaluator evaluator, string code, bool success, params string[] expectedOutput)
 {
     TestOutput(window, evaluator, code, success, null, true, 3000, expectedOutput);
 }