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