public void CustomCommandsRequiredPackages() { using (var app = new PythonVisualStudioApp()) using (var dis = app.SelectDefaultInterpreter(PythonVersion, "virtualenv")) { PythonProjectNode node; EnvDTE.Project proj; OpenProject(app, "CommandRequirePackages.sln", out node, out proj); string envName; var env = app.CreateVirtualEnvironment(proj, out envName); env.Select(); app.Dte.ExecuteCommand("Python.ActivateEnvironment"); // Ensure that no error dialog appears app.WaitForNoDialog(TimeSpan.FromSeconds(5.0)); // First, execute the command and cancel it. var task = ExecuteAsync(node, "Require Packages"); try { var dialogHandle = app.WaitForDialog(task); if (dialogHandle == IntPtr.Zero) { if (task.IsFaulted && task.Exception != null) { Assert.Fail("Unexpected exception in package install confirmation dialog:\n{0}", task.Exception); } else { Assert.AreNotEqual(IntPtr.Zero, dialogHandle); } } using (var dialog = new AutomationDialog(app, AutomationElement.FromHandle(dialogHandle))) { var label = dialog.FindByAutomationId("CommandLink_1000"); Assert.IsNotNull(label); string expectedLabel = "The following packages will be installed using pip:\r\n" + "\r\n" + "ptvsd\r\n" + "azure==0.1"; ; Assert.AreEqual(expectedLabel, label.Current.HelpText); dialog.Cancel(); try { task.Wait(1000); Assert.Fail("Command was not canceled after dismissing the package install confirmation dialog"); } catch (AggregateException ex) { if (!(ex.InnerException is TaskCanceledException)) { throw; } } } } finally { if (!task.IsCanceled && !task.IsCompleted && !task.IsFaulted) { if (task.Wait(10000)) { task.Dispose(); } } else { task.Dispose(); } } // Then, execute command and allow it to proceed. task = ExecuteAsync(node, "Require Packages"); try { var dialogHandle = app.WaitForDialog(task); if (dialogHandle == IntPtr.Zero) { if (task.IsFaulted && task.Exception != null) { Assert.Fail("Unexpected exception in package install confirmation dialog:\n{0}", task.Exception); } else { Assert.AreNotEqual(IntPtr.Zero, dialogHandle); } } using (var dialog = new AutomationDialog(app, AutomationElement.FromHandle(dialogHandle))) { dialog.ClickButtonAndClose("CommandLink_1000", nameIsAutomationId: true); } task.Wait(); var ver = PythonVersion.Version.ToVersion(); ExpectOutputWindowText(app, string.Format("pass {0}.{1}", ver.Major, ver.Minor)); } finally { if (!task.IsCanceled && !task.IsCompleted && !task.IsFaulted) { if (task.Wait(10000)) { task.Dispose(); } } else { task.Dispose(); } } } }
public void RenameProjectToExisting() { using (var app = new PythonVisualStudioApp()) { var project = app.OpenProject(@"TestData\RenameProjectTestUI.sln"); app.OpenSolutionExplorer(); var window = app.SolutionExplorerTreeView; // find Program.py, send copy & paste, verify copy of file is there var projectNode = window.FindItem("Solution 'RenameProjectTestUI' (1 project)", "HelloWorld"); // rename once, cancel renaming to existing file.... AutomationWrapper.Select(projectNode); Keyboard.PressAndRelease(Key.F2); System.Threading.Thread.Sleep(100); Keyboard.Type("HelloWorldExisting"); System.Threading.Thread.Sleep(100); Keyboard.PressAndRelease(Key.Enter); IntPtr dialog = app.WaitForDialog(); VisualStudioApp.CheckMessageBox("HelloWorldExisting.pyproj", "overwrite"); // rename again, don't cancel... AutomationWrapper.Select(projectNode); Keyboard.PressAndRelease(Key.F2); System.Threading.Thread.Sleep(100); Keyboard.Type("HelloWorldExisting"); System.Threading.Thread.Sleep(100); Keyboard.PressAndRelease(Key.Enter); dialog = app.WaitForDialog(); VisualStudioApp.CheckMessageBox(MessageBoxButton.Yes, "HelloWorldExisting.pyproj", "overwrite"); Assert.IsNotNull(window.WaitForItem("Solution 'RenameProjectTestUI' (1 project)", "HelloWorldExisting")); } }
public void RenameItemsTest() { using (var app = new PythonVisualStudioApp()) { var project = app.OpenProject(@"TestData\RenameItemsTestUI.sln"); var window = app.OpenSolutionExplorer(); // find Program.py, send copy & paste, verify copy of file is there var node = window.FindChildOfProject(project, "Program.py"); // rename once, cancel renaming to existing file.... node.Select(); Keyboard.PressAndRelease(Key.F2); System.Threading.Thread.Sleep(100); Keyboard.PressAndRelease(Key.A, Key.LeftCtrl); Keyboard.Type("NewName.txt"); System.Threading.Thread.Sleep(100); Keyboard.PressAndRelease(Key.Enter); IntPtr dialog = app.WaitForDialog(); VisualStudioApp.CheckMessageBox(MessageBoxButton.Cancel, "file name extension"); // rename again, don't cancel... node.Select(); Keyboard.PressAndRelease(Key.F2); System.Threading.Thread.Sleep(100); Keyboard.PressAndRelease(Key.A, Key.LeftCtrl); Keyboard.Type("NewName.txt"); System.Threading.Thread.Sleep(100); Keyboard.PressAndRelease(Key.Enter); dialog = app.WaitForDialog(); VisualStudioApp.CheckMessageBox(MessageBoxButton.Yes, "file name extension"); Assert.IsNotNull(window.WaitForChildOfProject(project, "NewName.txt")); } }
public void TestLaunchWithErrorsRun() { using (var app = new PythonVisualStudioApp()) { var project = app.OpenProject(@"TestData\ErrorProject.sln"); GetOptions().PromptBeforeRunningWithBuildErrorSetting = true; var debug3 = (Debugger3)app.Dte.Debugger; ThreadPool.QueueUserWorkItem(x => debug3.Go(true)); var dialog = new PythonLaunchWithErrorsDialog(app.WaitForDialog()); dialog.No(); // make sure we don't go into debug mode for (int i = 0; i < 10; i++) { Assert.AreEqual(dbgDebugMode.dbgDesignMode, app.Dte.Debugger.CurrentMode); System.Threading.Thread.Sleep(100); } WaitForMode(app, dbgDebugMode.dbgDesignMode); } }
public void NewProfilingSession() { PythonPaths.Python27.AssertInstalled(); var testFile = TestData.GetPath(@"TestData\ProfileTest\Program.py"); Assert.IsTrue(File.Exists(testFile), "ProfileTest\\Program.py does not exist"); using (var app = new PythonVisualStudioApp()) { app.OpenPythonPerformance(); app.PythonPerformanceExplorerToolBar.NewPerfSession(); var profiling = (IPythonProfiling)app.Dte.GetObject("PythonProfiling"); app.OpenPythonPerformance(); var perf = app.PythonPerformanceExplorerTreeView.WaitForItem("Performance *"); Assert.IsNotNull(perf); var session = profiling.GetSession(1); Assert.IsNotNull(session); Mouse.MoveTo(perf.GetClickablePoint()); Mouse.DoubleClick(System.Windows.Input.MouseButton.Left); // wait for the dialog, set some settings, save them. using (var perfTarget = new PythonPerfTarget(app.WaitForDialog())) { perfTarget.SelectProfileScript(); perfTarget.InterpreterComboBox.SelectItem("Python 2.7"); perfTarget.ScriptName = testFile; perfTarget.WorkingDir = Path.GetDirectoryName(testFile); try { perfTarget.Ok(); } catch (ElementNotEnabledException) { Assert.Fail("Settings were invalid:\n ScriptName = {0}\n Interpreter = {1}", perfTarget.ScriptName, perfTarget.SelectedInterpreter); } } app.WaitForDialogDismissed(); Mouse.MoveTo(perf.GetClickablePoint()); Mouse.DoubleClick(System.Windows.Input.MouseButton.Left); // re-open the dialog, verify the settings using (var perfTarget = new PythonPerfTarget(app.WaitForDialog())) { Assert.AreEqual("Python 2.7", perfTarget.SelectedInterpreter); Assert.AreEqual(TestData.GetPath(@"TestData\ProfileTest\Program.py"), perfTarget.ScriptName); } } }
private IPythonProfileSession LaunchSession( PythonVisualStudioApp app, Func<IPythonProfileSession> creator ) { // Ensure the performance window has been opened, which will make // the app clean up all sessions when it is disposed. app.OpenPythonPerformance(); IPythonProfileSession session = null; var task = Task.Factory.StartNew(() => { session = creator(); // Must fault the task to abort the wait throw new Exception(); }); var dialog = app.WaitForDialog(task); if (dialog != IntPtr.Zero) { using (var saveDialog = new SaveDialog(app, AutomationElement.FromHandle(dialog))) { var originalDestName = Path.Combine(SaveDirectory, Path.GetFileName(saveDialog.FileName)); var destName = originalDestName; while (File.Exists(destName)) { destName = string.Format("{0} {1}{2}", Path.GetFileNameWithoutExtension(originalDestName), Guid.NewGuid(), Path.GetExtension(originalDestName) ); } saveDialog.FileName = destName; saveDialog.Save(); try { task.Wait(TimeSpan.FromSeconds(5.0)); Assert.Fail("Task did not fault"); } catch (AggregateException) { } } } else { // Ensure the exception is observed var ex = task.Exception; } Assert.IsNotNull(session, "Session was not correctly initialized"); return session; }
public void WebProjectInstallOnNew() { using (var app = new PythonVisualStudioApp()) { app.OptionsService.DefaultInterpreter.PipUninstall("bottle"); var t = Task.Run(() => app.CreateProject( PythonVisualStudioApp.TemplateLanguageName, PythonVisualStudioApp.BottleWebProjectTemplate, TestData.GetTempPath(), "WebProjectInstallOnNew", suppressUI: false )); using (var dlg = new AutomationDialog(app, AutomationElement.FromHandle(app.WaitForDialog(t)))) { // Install to active environment dlg.ClickButtonAndClose("CommandLink_1001", nameIsAutomationId: true); } var project = t.WaitAndUnwrapExceptions(); Assert.AreSame(app.OptionsService.DefaultInterpreter, project.GetPythonProject().ActiveInterpreter); for (int retries = 60; retries > 0; --retries) { if (project.GetPythonProject().ActiveInterpreter.FindModules("bottle").Any()) { break; } Thread.Sleep(1000); } AssertUtil.ContainsExactly(project.GetPythonProject().ActiveInterpreter.FindModules("bottle"), "bottle"); app.OptionsService.DefaultInterpreter.PipUninstall("bottle"); } }
public void WebProjectCreateVirtualEnvOnNew() { using (var app = new PythonVisualStudioApp()) { var t = Task.Run(() => app.CreateProject( PythonVisualStudioApp.TemplateLanguageName, PythonVisualStudioApp.FlaskWebProjectTemplate, TestData.GetTempPath(), "WebProjectCreateVirtualEnvOnNew", suppressUI: false )); using (var dlg = new AutomationDialog(app, AutomationElement.FromHandle(app.WaitForDialog(t)))) { // Create a virtual environment dlg.ClickButtonAndClose("CommandLink_1000", nameIsAutomationId: true); } using (var dlg = new AutomationDialog(app, AutomationElement.FromHandle(app.WaitForDialog(t)))) { dlg.ClickButtonByAutomationId("Create"); dlg.ClickButtonAndClose("Close", nameIsAutomationId: true); } var project = t.WaitAndUnwrapExceptions(); var contextProvider = app.ComponentModel.GetService<VsProjectContextProvider>(); for (int retries = 20; retries > 0; --retries) { if (contextProvider.IsProjectSpecific(project.GetPythonProject().ActiveInterpreter.Configuration)) { break; } Thread.Sleep(1000); } Assert.IsTrue(contextProvider.IsProjectSpecific(project.GetPythonProject().ActiveInterpreter.Configuration), "Did not have virtualenv"); for (int retries = 60; retries > 0; --retries) { if (project.GetPythonProject().ActiveInterpreter.FindModules("flask").Any()) { break; } Thread.Sleep(1000); } AssertUtil.ContainsExactly(project.GetPythonProject().ActiveInterpreter.FindModules("flask"), "flask"); } }