public void ShouldWarnOnRun() { var sln = new ProjectDefinition( "HelloWorld", PythonProject, Compile("app", "print \"hello\"") ).Generate(); using (var vs = sln.ToMockVs()) using (var analyzerChanged = new AutoResetEvent(false)) { var project = vs.GetProject("HelloWorld").GetPythonProject(); project.ProjectAnalyzerChanged += (s, e) => analyzerChanged.Set(); var v27 = InterpreterFactoryCreator.CreateInterpreterFactory(new InterpreterFactoryCreationOptions { LanguageVersion = new Version(2, 7), PrefixPath = "C:\\Python27", InterpreterPath = "C:\\Python27\\python.exe" }); var v34 = InterpreterFactoryCreator.CreateInterpreterFactory(new InterpreterFactoryCreationOptions { LanguageVersion = new Version(3, 4), PrefixPath = "C:\\Python34", InterpreterPath = "C:\\Python34\\python.exe" }); var uiThread = (UIThreadBase)project.GetService(typeof(UIThreadBase)); uiThread.Invoke(() => { project.Interpreters.AddInterpreter(v27); project.Interpreters.AddInterpreter(v34); }); project.SetInterpreterFactory(v27); Assert.IsTrue(analyzerChanged.WaitOne(10000), "Timed out waiting for analyzer change #1"); uiThread.Invoke(() => project.GetAnalyzer()).WaitForCompleteAnalysis(_ => true); Assert.IsFalse(project.ShouldWarnOnLaunch, "Should not warn on 2.7"); project.SetInterpreterFactory(v34); Assert.IsTrue(analyzerChanged.WaitOne(10000), "Timed out waiting for analyzer change #2"); uiThread.Invoke(() => project.GetAnalyzer()).WaitForCompleteAnalysis(_ => true); Assert.IsTrue(project.ShouldWarnOnLaunch, "Expected warning on 3.4"); project.SetInterpreterFactory(v27); Assert.IsTrue(analyzerChanged.WaitOne(10000), "Timed out waiting for analyzer change #3"); uiThread.Invoke(() => project.GetAnalyzer()).WaitForCompleteAnalysis(_ => true); Assert.IsFalse(project.ShouldWarnOnLaunch, "Expected warning to go away on 2.7"); } }
public IEnumerable <IPythonInterpreterFactory> GetInterpreterFactories() { yield return(InterpreterFactoryCreator.CreateInterpreterFactory(new VisualStudioInterpreterConfiguration( "Test Interpreter", "Python 2.6 32-bit", PathUtils.GetParent(_pythonExe), _pythonExe, _pythonWinExe, "PYTHONPATH", InterpreterArchitecture.x86, new Version(2, 6), InterpreterUIMode.CannotBeDefault ), new InterpreterFactoryCreationOptions { WatchFileSystem = false })); }
public void InvalidInterpreterVersion() { try { var lv = new Version(1, 0).ToLanguageVersion(); Assert.Fail("Expected InvalidOperationException"); } catch (InvalidOperationException) { } try { InterpreterFactoryCreator.CreateInterpreterFactory(new InterpreterFactoryCreationOptions { Id = Guid.NewGuid(), LanguageVersionString = "1.0" }); Assert.Fail("Expected ArgumentException"); } catch (ArgumentException ex) { // Expect version number in message AssertUtil.Contains(ex.Message, "1.0"); } }
public IPythonInterpreterFactory EnsureFactory() { if (Factory == null) { lock (this) { if (Factory == null) { Factory = InterpreterFactoryCreator.CreateInterpreterFactory( Configuration, new InterpreterFactoryCreationOptions { PackageManager = new PipPackageManager(), WatchFileSystem = true } ); } } } return(Factory); }
public void InvalidInterpreterVersion() { try { var lv = new Version(1, 0).ToLanguageVersion(); Assert.Fail("Expected InvalidOperationException"); } catch (InvalidOperationException) { } try { InterpreterFactoryCreator.CreateInterpreterFactory(new VisualStudioInterpreterConfiguration( Guid.NewGuid().ToString(), "Test Interpreter", version: new Version(1, 0) )); Assert.Fail("Expected ArgumentException"); } catch (ArgumentException ex) { // Expect version number in message AssertUtil.Contains(ex.Message, "1.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 + ">" ); }
public void BadInterpreterPath() { // http://pytools.codeplex.com/workitem/662 var emptyFact = InterpreterFactoryCreator.CreateInterpreterFactory( new InterpreterConfiguration( "Test Interpreter", "Test Interpreter", null, "C:\\Does\\Not\\Exist\\Some\\Interpreter.exe", null, null, null, ProcessorArchitecture.None, new Version(2, 7) ), new InterpreterFactoryCreationOptions() ); 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 CheckObsoleteGenerateFunction() { var path = PythonPaths.Versions.LastOrDefault(p => p != null && p.IsCPython); path.AssertInstalled(); var factory = InterpreterFactoryCreator.CreateInterpreterFactory( new InterpreterConfiguration( path.Id, "Test Interpreter", path.PrefixPath, path.InterpreterPath, path.InterpreterPath, path.LibPath, "PYTHONPATH", path.Isx64 ? ProcessorArchitecture.Amd64 : ProcessorArchitecture.X86, path.Version.ToVersion() ), new InterpreterFactoryCreationOptions { WatchLibraryForNewModules = false } ); var tcs = new TaskCompletionSource <int>(); var beforeProc = Process.GetProcessesByName("Microsoft.PythonTools.Analyzer"); var request = new PythonTypeDatabaseCreationRequest { Factory = factory, OutputPath = TestData.GetTempPath(randomSubPath: true), SkipUnchanged = true, OnExit = tcs.SetResult }; Console.WriteLine("OutputPath: {0}", request.OutputPath); #pragma warning disable 618 PythonTypeDatabase.Generate(request); #pragma warning restore 618 int expected = 0; if (!tcs.Task.Wait(TimeSpan.FromMinutes(1.0))) { var proc = Process.GetProcessesByName("Microsoft.PythonTools.Analyzer") .Except(beforeProc) .ToArray(); // Ensure we actually started running Assert.AreNotEqual(0, proc.Length, "Process is not running"); expected = -1; // Kill the process foreach (var p in proc) { Console.WriteLine("Killing process {0}", p.Id); p.Kill(); } Assert.IsTrue(tcs.Task.Wait(TimeSpan.FromMinutes(1.0)), "Process did not die"); } Assert.AreEqual(expected, tcs.Task.Result, "Incorrect exit code"); }
/// <summary> /// Creates the factory for Canopy's base (App) interpreter. This /// factory is not displayed to the user, but is used to maintain the /// completion database. /// </summary> public static PythonInterpreterFactoryWithDatabase CreateBase( string basePath, string canopyVersion, Version languageVersion ) { var interpPath = FindFile(basePath, CanopyInterpreterFactoryConstants.ConsoleExecutable); var winInterpPath = FindFile(basePath, CanopyInterpreterFactoryConstants.WindowsExecutable); var libPath = Path.Combine(basePath, CanopyInterpreterFactoryConstants.LibrarySubPath); if (!File.Exists(interpPath)) { throw new FileNotFoundException(interpPath); } if (!File.Exists(winInterpPath)) { throw new FileNotFoundException(winInterpPath); } if (!Directory.Exists(libPath)) { throw new DirectoryNotFoundException(libPath); } // Detect the architecture and select the appropriate id var arch = NativeMethods.GetBinaryType(interpPath); var id = (arch == ProcessorArchitecture.Amd64) ? CanopyInterpreterFactoryConstants.BaseGuid64 : CanopyInterpreterFactoryConstants.BaseGuid32; // Make the description string look like "Base Canopy 1.1.0.46 (2.7 32-bit)" var description = "Base Canopy"; if (!string.IsNullOrEmpty(canopyVersion)) { description += " " + canopyVersion; } description += string.Format(" ({0} ", languageVersion); if (arch == ProcessorArchitecture.Amd64) { description += " 64-bit)"; } else { description += " 32-bit)"; } return(InterpreterFactoryCreator.CreateInterpreterFactory( new InterpreterConfiguration( basePath, description, basePath, interpPath, winInterpPath, libPath, CanopyInterpreterFactoryConstants.PathEnvironmentVariableName, arch, languageVersion, InterpreterUIMode.SupportsDatabase ), new InterpreterFactoryCreationOptions { WatchLibraryForNewModules = true } )); }