Beispiel #1
0
        public void WebProjectInstallOnNew(PythonVisualStudioApp app)
        {
            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");
        }
Beispiel #2
0
        public void WebProjectCreateVirtualEnvOnNew()
        {
            using (var app = new VisualStudioApp()) {
                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 = TaskExt.WaitAndUnwrapExceptions(t);

                var provider = project.Properties.Item("InterpreterFactoryProvider").Value as MSBuildProjectInterpreterFactoryProvider;
                for (int retries = 20; retries > 0; --retries)
                {
                    if (provider.IsProjectSpecific(provider.ActiveInterpreter))
                    {
                        break;
                    }
                    Thread.Sleep(1000);
                }
                Assert.IsTrue(provider.IsProjectSpecific(provider.ActiveInterpreter), "Did not have virtualenv");

                for (int retries = 60; retries > 0; --retries)
                {
                    if (InterpreterExt.FindModules(provider.ActiveInterpreter, "flask").Any())
                    {
                        break;
                    }
                    Thread.Sleep(1000);
                }
                AssertUtil.ContainsExactly(
                    InterpreterExt.FindModules(provider.ActiveInterpreter, "flask"),
                    "flask"
                    );
            }
        }
Beispiel #3
0
        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");
            }
        }
Beispiel #4
0
        public void WebProjectInstallOnNew()
        {
            using (var app = new PythonVisualStudioApp()) {
                TaskExt.WaitAndUnwrapExceptions(
                    Pip.Uninstall(app.ServiceProvider, app.InterpreterService.DefaultInterpreter, "bottle", false)
                    );

                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 = TaskExt.WaitAndUnwrapExceptions(t);

                var provider = project.Properties.Item("InterpreterFactoryProvider").Value as MSBuildProjectInterpreterFactoryProvider;

                Assert.AreSame(app.InterpreterService.DefaultInterpreter, provider.ActiveInterpreter);

                for (int retries = 60; retries > 0; --retries)
                {
                    if (InterpreterExt.FindModules(provider.ActiveInterpreter, "bottle").Any())
                    {
                        break;
                    }
                    Thread.Sleep(1000);
                }
                AssertUtil.ContainsExactly(
                    InterpreterExt.FindModules(provider.ActiveInterpreter, "bottle"),
                    "bottle"
                    );

                TaskExt.WaitAndUnwrapExceptions(
                    Pip.Uninstall(app.ServiceProvider, app.InterpreterService.DefaultInterpreter, "bottle", false)
                    );
            }
        }
Beispiel #5
0
        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();
                        }
                    }
                }
        }