private static void WaitForReport(IPythonProfiling profiling, IPythonProfileSession session, PythonVisualStudioApp app, out string reportFilename) { while (profiling.IsProfiling) { Thread.Sleep(100); } var report = session.GetReport(1); var filename = report.Filename; Assert.IsTrue(filename.Contains("HelloWorld")); app.OpenPythonPerformance(); var pyPerf = app.PythonPerformanceExplorerTreeView; Assert.IsNotNull(pyPerf); var item = pyPerf.FindItem("HelloWorld *", "Reports"); var child = item.FindFirst(System.Windows.Automation.TreeScope.Descendants, Condition.TrueCondition); var childName = child.GetCurrentPropertyValue(AutomationElement.NameProperty) as string; reportFilename = report.Filename; Assert.IsTrue(childName.StartsWith("HelloWorld")); child.SetFocus(); Keyboard.PressAndRelease(System.Windows.Input.Key.Delete); }
private static void WaitForReport(IPythonProfiling profiling, IPythonProfileSession session, out IPythonPerformanceReport report, PythonVisualStudioApp app, out AutomationElement child) { while (profiling.IsProfiling) { Thread.Sleep(100); } report = session.GetReport(1); var filename = report.Filename; Assert.IsTrue(filename.Contains("HelloWorld")); app.OpenPythonPerformance(); var pyPerf = app.PythonPerformanceExplorerTreeView; Assert.IsNotNull(pyPerf); var item = pyPerf.WaitForItem("HelloWorld *", "Reports"); child = item.FindFirst(TreeScope.Descendants, Condition.TrueCondition); var childName = (string)child.GetCurrentPropertyValue(AutomationElement.NameProperty); Assert.IsTrue(childName.StartsWith("HelloWorld")); AutomationWrapper.EnsureExpanded(child); }
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); } } }
public void DeleteMultipleSessions() { using (var app = new PythonVisualStudioApp()) { app.Dte.Solution.Close(false); app.OpenPythonPerformance(); app.PythonPerformanceExplorerToolBar.NewPerfSession(); app.PythonPerformanceExplorerToolBar.NewPerfSession(); var profiling = (IPythonProfiling)app.Dte.GetObject("PythonProfiling"); app.OpenPythonPerformance(); var perf = app.PythonPerformanceExplorerTreeView.WaitForItem("Performance *"); Assert.IsNotNull(perf); var perf2 = app.PythonPerformanceExplorerTreeView.WaitForItem("Performance1 *"); AutomationWrapper.Select(perf); // Cannot use AddToSelection because the tree view declares that // it does not support multi-select, even though it does. // AutomationWrapper.AddToSelection(perf2); Mouse.MoveTo(perf2.GetClickablePoint()); try { Keyboard.Press(System.Windows.Input.Key.LeftCtrl); Mouse.Click(System.Windows.Input.MouseButton.Left); } finally { Keyboard.Release(System.Windows.Input.Key.LeftCtrl); } var dialog = AutomationElement.FromHandle(app.OpenDialogWithDteExecuteCommand("Edit.Delete")).AsWrapper(); dialog.ClickButtonByName("Delete"); Assert.IsNull(app.PythonPerformanceExplorerTreeView.WaitForItemRemoved("Performance *")); Assert.IsNull(app.PythonPerformanceExplorerTreeView.WaitForItemRemoved("Performance1 *")); } }
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; }