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 )); } }
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)); } }
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 + ">" ); }