예제 #1
0
        public void CustomCommandsRunProcessInRepl() {
            using (var app = new PythonVisualStudioApp()) {
                PythonProjectNode node;
                EnvDTE.Project proj;
                OpenProject(app, "Commands3.sln", out node, out proj);

                Execute(node, "Write to Repl");

                using (var repl = app.GetInteractiveWindow("Test Repl")) {
                    Assert.IsNotNull(repl, "Could not find repl window");
                    repl.WaitForTextEnd(
                        string.Format("({0}, {1})", PythonVersion.Configuration.Version.Major, PythonVersion.Configuration.Version.Minor),
                        ">"
                    );
                }
            }
        }
예제 #2
0
        public void CustomCommandsRunInRepl() {
            using (var app = new PythonVisualStudioApp()) {
                PythonProjectNode node;
                EnvDTE.Project proj;
                OpenProject(app, "Commands1.sln", out node, out proj);

                Execute(node, "Test Command 2");

                using (var repl = app.GetInteractiveWindow("Test Repl")) {
                    Assert.IsNotNull(repl, "Could not find repl window");
                    repl.WaitForTextEnd(
                        "Program.py completed",
                        ">"
                    );
                }

                app.Dte.Solution.Close();

                using (var repl = app.GetInteractiveWindow("Test Repl")) {
                    Assert.IsNull(repl, "Repl window was not closed");
                }
            }
        }
예제 #3
0
        public void CustomCommandsReplWithResourceLabel() {
            using (var app = new PythonVisualStudioApp()) {
                PythonProjectNode node;
                EnvDTE.Project proj;
                OpenProject(app, "Commands2.sln", out node, out proj);

                Execute(node, "Command from Resource");

                using (var repl = app.GetInteractiveWindow("Repl from Resource")) {
                    Assert.IsNotNull(repl, "Could not find repl window");
                    repl.WaitForTextEnd(
                        "Program.py completed",
                        ">"
                    );
                }

                using (var repl = app.GetInteractiveWindow("resource:PythonToolsUITests;PythonToolsUITests.Resources;ReplName")) {
                    Assert.IsNull(repl);
                }
            }
        }
예제 #4
0
        private void EnvironmentReplWorkingDirectoryTest(
            PythonVisualStudioApp app,
            EnvDTE.Project project,
            TreeNode env,
            string envName
        ) {
            var path1 = Path.Combine(Path.GetDirectoryName(project.FullName), Guid.NewGuid().ToString("N"));
            var path2 = Path.Combine(Path.GetDirectoryName(project.FullName), Guid.NewGuid().ToString("N"));
            Directory.CreateDirectory(path1);
            Directory.CreateDirectory(path2);

            env.Select();
            app.Dte.ExecuteCommand("Python.Interactive");

            var window = app.GetInteractiveWindow(string.Format("{0} Interactive", envName));
            Assert.IsNotNull(window, string.Format("Failed to find '{0} Interactive'", envName));
            try {
                app.ServiceProvider.GetUIThread().Invoke(() => project.GetPythonProject().SetProjectProperty("WorkingDirectory", path1));

                window.Reset();
                window.ReplWindow.Evaluator.ExecuteText("import os; os.getcwd()").Wait();
                window.WaitForTextEnd(
                    string.Format("'{0}'", path1.Replace("\\", "\\\\")),
                    ">>>"
                );

                app.ServiceProvider.GetUIThread().Invoke(() => project.GetPythonProject().SetProjectProperty("WorkingDirectory", path2));

                window.Reset();
                window.ReplWindow.Evaluator.ExecuteText("import os; os.getcwd()").Wait();
                window.WaitForTextEnd(
                    string.Format("'{0}'", path2.Replace("\\", "\\\\")),
                    ">>>"
                );
            } finally {
                window.Close();
            }
        }
예제 #5
0
        public void DjangoCollectStaticFilesCommand() {
            using (var app = new PythonVisualStudioApp()) {
                var service = app.GetService<IComponentModel>(typeof(SComponentModel)).GetService<IInterpreterOptionsService>();

                var envWithDjango = service.Interpreters.LastOrDefault(env => env.FindModulesAsync("django").WaitAndUnwrapExceptions().Contains("django"));
                if (envWithDjango == null) {
                    Assert.Inconclusive("No available environments have Django installed");
                }

                using (var dis = new DefaultInterpreterSetter(envWithDjango)) {
                    var project = app.OpenProject("TestData\\DjangoApplication1\\DjangoApplication1.sln");
                    app.SolutionExplorerTreeView.SelectProject(project);

                    app.Dte.ExecuteCommand("Project.CollectStaticFiles");

                    var console = app.GetInteractiveWindow("Django Management Console - " + project.Name);
                    Assert.IsNotNull(console);

                    console.WaitForTextEnd("The Python REPL process has exited", ">>> ");

                    Assert.IsTrue(console.Text.Contains("0 static files copied"));
                }
            }
        }
예제 #6
0
        public void StartNewApp() {
            using (var app = new PythonVisualStudioApp()) {
                var project = app.CreateProject(
                    PythonVisualStudioApp.TemplateLanguageName,
                    PythonVisualStudioApp.DjangoWebProjectTemplate,
                    TestData.GetTempPath(),
                    "StartNewApp"
                );
                app.SolutionExplorerTreeView.SelectProject(project);

                using (var newAppDialog = NewAppDialog.FromDte(app)) {
                    newAppDialog.AppName = "Fob";
                    newAppDialog.OK();
                }

                app.SolutionExplorerTreeView.WaitForItem(
                    app.Dte.Solution.FullName,
                    app.Dte.Solution.Projects.Item(1).Name,
                    "Fob",
                    "models.py"
                );

                var appFolder = project.ProjectItems.Item("Fob");
                Assert.IsNotNull(appFolder.Collection.Item("models.py"));
                Assert.IsNotNull(appFolder.Collection.Item("tests.py"));
                Assert.IsNotNull(appFolder.Collection.Item("views.py"));
                Assert.IsNotNull(appFolder.Collection.Item("__init__.py"));

                app.SolutionExplorerTreeView.SelectProject(project);
                app.Dte.ExecuteCommand("Project.ValidateDjangoApp");

                var console = app.GetInteractiveWindow("Django Management Console - " + project.Name);
                Assert.IsNotNull(console);
                console.WaitForTextEnd("Executing manage.py validate", "0 errors found", "The Python REPL process has exited", ">>> ");

                app.SolutionExplorerTreeView.SelectProject(project);

                using (var newItem = NewItemDialog.FromDte(app)) {
                    AutomationWrapper.Select(newItem.ProjectTypes.FindItem("HTML Page"));
                    newItem.FileName = "NewPage.html";
                    newItem.OK();
                }

                System.Threading.Thread.Sleep(1000);

                Assert.IsNotNull(project.ProjectItems.Item("NewPage.html"));
            }
        }