当前位置: 首页>>代码示例>>C#>>正文


C# PythonVisualStudioApp.OnDispose方法代码示例

本文整理汇总了C#中TestUtilities.UI.Python.PythonVisualStudioApp.OnDispose方法的典型用法代码示例。如果您正苦于以下问题:C# PythonVisualStudioApp.OnDispose方法的具体用法?C# PythonVisualStudioApp.OnDispose怎么用?C# PythonVisualStudioApp.OnDispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TestUtilities.UI.Python.PythonVisualStudioApp的用法示例。


在下文中一共展示了PythonVisualStudioApp.OnDispose方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AutomaticBraceCompletion

        public void AutomaticBraceCompletion() {
            using (var app = new PythonVisualStudioApp()) {
                var project = app.OpenProject(@"TestData\AutomaticBraceCompletion.sln");

                bool oldState = EnableAutoBraceCompletion(app, true);
                app.OnDispose(() => EnableAutoBraceCompletion(app, oldState));

                // check that braces get auto completed
                AutoBraceCompetionTest(app, project, "foo(", "foo()");
                AutoBraceCompetionTest(app, project, "foo[", "foo[]");
                AutoBraceCompetionTest(app, project, "foo{", "foo{}");
                AutoBraceCompetionTest(app, project, "\"foo", "\"foo\"");
                AutoBraceCompetionTest(app, project, "'foo", "'foo'");

                // check that braces get not autocompleted in comments and strings
                AutoBraceCompetionTest(app, project, "\"foo(\"", "\"foo(\"");
                AutoBraceCompetionTest(app, project, "#foo(", "#foo(");
                AutoBraceCompetionTest(app, project, "\"\"\"\rfoo(\r\"\"\"\"", "\"\"\"\r\nfoo(\r\n\"\"\"\"");

                // check that end braces gets skiped
                AutoBraceCompetionTest(app, project, "foo(bar)", "foo(bar)");
                AutoBraceCompetionTest(app, project, "foo[bar]", "foo[bar]");
                AutoBraceCompetionTest(app, project, "foo{bar}", "foo{bar}");
                AutoBraceCompetionTest(app, project, "\"foo\"", "\"foo\"");
                AutoBraceCompetionTest(app, project, "'foo'", "'foo'");
                AutoBraceCompetionTest(app, project, "foo({[\"\"]})", "foo({[\"\"]})");
            }
        }
开发者ID:jsschultz,项目名称:PTVS,代码行数:28,代码来源:EditorTests.cs

示例2: DeferredSaveWithDot

        public void DeferredSaveWithDot() {
            string fullname;
            using (var app = new PythonVisualStudioApp()) {
                // http://pytools.codeplex.com/workitem/623
                // enable deferred saving on projects
                var props = app.Dte.get_Properties("Environment", "ProjectsAndSolution");
                var prevValue = props.Item("SaveNewProjects").Value;
                props.Item("SaveNewProjects").Value = false;
                app.OnDispose(() => { props.Item("SaveNewProjects").Value = prevValue; });


                using (var newProjDialog = app.FileNewProject()) {
                    newProjDialog.FocusLanguageNode();

                    var consoleApp = newProjDialog.ProjectTypes.FindItem("Python Application");
                    consoleApp.Select();
                    newProjDialog.ProjectName = "Fob.Oar";
                    newProjDialog.OK();
                }

                // wait for new solution to load...
                for (int i = 0; i < 100 && app.Dte.Solution.Projects.Count == 0; i++) {
                    System.Threading.Thread.Sleep(1000);
                }

                using (var saveDialog = AutomationDialog.FromDte(app, "File.SaveAll")) {
                    saveDialog.ClickButtonAndClose("Save");
                }

                fullname = app.Dte.Solution.FullName;
            }

            try {
                // Delete the created directory after the solution has been
                // closed.
                Directory.Delete(Path.GetDirectoryName(fullname), true);
            } catch {
            }
        }
开发者ID:wenh123,项目名称:PTVS,代码行数:39,代码来源:UITests.cs

示例3: DeleteVirtualEnv

        public void DeleteVirtualEnv() {
            using (var app = new PythonVisualStudioApp())
            using (var dis = Init(app)) {
                var options = app.GetService<PythonToolsService>().GeneralOptions;
                var oldAutoAnalyze = options.AutoAnalyzeStandardLibrary;
                app.OnDispose(() => { options.AutoAnalyzeStandardLibrary = oldAutoAnalyze; options.Save(); });
                options.AutoAnalyzeStandardLibrary = false;
                options.Save();

                var project = CreateTemporaryProject(app);

                string envName, envPath;
                TreeNode env;
                using (var ps = new ProcessScope("Microsoft.PythonTools.Analyzer")) {
                    env = app.CreateVirtualEnvironment(project, out envName, out envPath);

                    Assert.IsFalse(ps.WaitForNewProcess(TimeSpan.FromSeconds(10)).Any(), "Unexpected analyzer processes");
                }

                // Need to wait some more for the database to be loaded.
                app.WaitForNoDialog(TimeSpan.FromSeconds(10.0));

                env.Select();
                using (var removeDeleteDlg = RemoveItemDialog.FromDte(app)) {
                    removeDeleteDlg.Delete();
                }

                app.WaitForNoDialog(TimeSpan.FromSeconds(5.0));

                app.OpenSolutionExplorer().WaitForChildOfProjectRemoved(
                    project,
                    SR.GetString(SR.Environments),
                    envName
                );

                var projectHome = (string)project.Properties.Item("ProjectHome").Value;
                envPath = Path.Combine(projectHome, envPath);
                for (int retries = 10;
                    Directory.Exists(envPath) && retries > 0;
                    --retries) {
                    Thread.Sleep(1000);
                }
                Assert.IsFalse(Directory.Exists(envPath), envPath);
            }
        }
开发者ID:KaushikCh,项目名称:PTVS,代码行数:45,代码来源:VirtualEnvTests.cs

示例4: CloudProjectTest

        private static void CloudProjectTest(string roleType, bool openServiceDefinition) {
            Assert.IsTrue(roleType == "Web" || roleType == "Worker", "Invalid roleType: " + roleType);

            Assembly asm = null;
            try {
                asm = Assembly.Load("Microsoft.VisualStudio.CloudService.Wizard,Version=1.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a");
            } catch {
                // Failed to load - we'll skip the test below
            }
            
            if (asm != null && asm.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false)
                .OfType<AssemblyFileVersionAttribute>()
                .Any(a => {
                    Version ver;
                    return Version.TryParse(a.Version, out ver) && ver < new Version(2, 5);
                })
            ) {
                Assert.Inconclusive("Test requires Microsoft Azure Tools 2.5 or later");
            }

            using (var app = new PythonVisualStudioApp())
            using (FileUtils.Backup(TestData.GetPath(@"TestData\CloudProject\ServiceDefinition.csdef"))) {
                app.OpenProject("TestData\\CloudProject.sln", expectedProjects: 3);

                var ccproj = app.Dte.Solution.Projects.Cast<Project>().FirstOrDefault(p => p.Name == "CloudProject");
                Assert.IsNotNull(ccproj);

                if (openServiceDefinition) {
                    var wnd = ccproj.ProjectItems.Item("ServiceDefinition.csdef").Open();
                    wnd.Activate();
                    app.OnDispose(() => wnd.Close());
                }

                IVsHierarchy hier;
                var sln = app.GetService<IVsSolution>(typeof(SVsSolution));
                ErrorHandler.ThrowOnFailure(sln.GetProjectOfUniqueName(ccproj.FullName, out hier));

                app.ServiceProvider.GetUIThread().InvokeAsync(() =>
                    PythonProjectNode.UpdateServiceDefinition(hier, roleType, roleType + "Role1", app.ServiceProvider)
                ).GetAwaiter().GetResult();

                var doc = new XmlDocument();
                for (int retries = 5; retries > 0; --retries) {
                    try {
                        doc.Load(TestData.GetPath(@"TestData\CloudProject\ServiceDefinition.csdef"));
                        break;
                    } catch (IOException ex) {
                        Console.WriteLine("Exception while reading ServiceDefinition.csdef.{0}{1}", Environment.NewLine, ex);
                    } catch (XmlException) {
                        var copyTo = TestData.GetPath(@"TestData\CloudProject\" + Path.GetRandomFileName());
                        File.Copy(TestData.GetPath(@"TestData\CloudProject\ServiceDefinition.csdef"), copyTo);
                        Console.WriteLine("Copied file to " + copyTo);
                        throw;
                    }
                    Thread.Sleep(100);
                }
                var ns = new XmlNamespaceManager(doc.NameTable);
                ns.AddNamespace("sd", "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition");
                doc.Save(Console.Out);

                var nav = doc.CreateNavigator();
                if (roleType == "Web") {
                    Assert.IsNotNull(nav.SelectSingleNode(
                        "/sd:ServiceDefinition/sd:WebRole[@name='WebRole1']/sd:Startup/sd:Task[@commandLine='ps.cmd ConfigureCloudService.ps1']",
                        ns
                    ));
                } else if (roleType == "Worker") {
                    Assert.IsNotNull(nav.SelectSingleNode(
                        "/sd:ServiceDefinition/sd:WorkerRole[@name='WorkerRole1']/sd:Startup/sd:Task[@commandLine='bin\\ps.cmd ConfigureCloudService.ps1']",
                        ns
                    ));
                    Assert.IsNotNull(nav.SelectSingleNode(
                        "/sd:ServiceDefinition/sd:WorkerRole[@name='WorkerRole1']/sd:Runtime/sd:EntryPoint/sd:ProgramEntryPoint[@commandLine='bin\\ps.cmd LaunchWorker.ps1']",
                        ns
                    ));
                }
            }
        }
开发者ID:jsschultz,项目名称:PTVS,代码行数:78,代码来源:WebProjectTests.cs

示例5: FormattingTest

        /// <summary>
        /// Runs a single formatting test
        /// </summary>
        /// <param name="filename">The filename of the document to perform formatting in (lives in FormattingTests.sln)</param>
        /// <param name="selection">The selection to format, or null if formatting the entire document</param>
        /// <param name="expectedText">The expected source code after the formatting</param>
        /// <param name="changedSpans">The spans which should be marked as changed in the buffer after formatting</param>
        private static void FormattingTest(
            string filename,
            Span? selection,
            string expectedText,
            Span[] changedSpans,
            Func<PythonToolsService, object> updateSettings,
            Action<PythonToolsService, object> revertSettings,
            Version version = null
        ) {
            using (var app = new PythonVisualStudioApp())
            using (version == null ? null : app.SelectDefaultInterpreter(PythonPaths.Versions.FirstOrDefault(v => v.Version.ToVersion() >= version))) {
                var o = updateSettings?.Invoke(app.PythonToolsService);
                if (revertSettings != null) {
                    app.OnDispose(() => revertSettings(app.PythonToolsService, o));
                }

                var project = app.OpenProject(@"TestData\FormattingTests\FormattingTests.sln");
                var item = project.ProjectItems.Item(filename);
                var window = item.Open();
                window.Activate();
                var doc = app.GetDocument(item.Document.FullName);

                var aggFact = app.ComponentModel.GetService<IViewTagAggregatorFactoryService>();
                var changeTags = aggFact.CreateTagAggregator<ChangeTag>(doc.TextView);

                // format the selection or document
                if (selection == null) {
                    DoFormatDocument();
                } else {
                    doc.Invoke(() => doc.TextView.Selection.Select(new SnapshotSpan(doc.TextView.TextBuffer.CurrentSnapshot, selection.Value), false));
                    DoFormatSelection();
                }

                // verify the contents are correct
                string actual = null;
                int steady = 50;
                for (int i = 0; i < 100; i++) {
                    actual = doc.TextView.TextBuffer.CurrentSnapshot.GetText();

                    if (expectedText == actual) {
                        if (--steady <= 0) {
                            break;
                        }
                    } else {
                        steady = 50;
                    }
                    System.Threading.Thread.Sleep(100);
                }
                Assert.AreEqual(expectedText, actual);

                // verify the change tags are correct
                var snapshot = doc.TextView.TextBuffer.CurrentSnapshot;
                var tags = changeTags.GetTags(
                    new SnapshotSpan(
                        doc.TextView.TextBuffer.CurrentSnapshot,
                        new Span(0, doc.TextView.TextBuffer.CurrentSnapshot.Length)
                    )
                );
                List<Span> result = new List<Span>();
                foreach (var tag in tags) {
                    result.Add(
                        new Span(
                            tag.Span.Start.GetPoint(doc.TextView.TextBuffer.CurrentSnapshot, PositionAffinity.Successor).Value.Position,
                            tag.Span.End.GetPoint(doc.TextView.TextBuffer.CurrentSnapshot, PositionAffinity.Successor).Value.Position
                        )
                    );
                }

                // dump the spans for creating tests easier
                foreach (var span in result) {
                    Console.WriteLine(span);
                }

                Assert.AreEqual(result.Count, changedSpans.Length);
                for (int i = 0; i < result.Count; i++) {
                    Assert.AreEqual(result[i], changedSpans[i]);
                }
            }
        }
开发者ID:jsschultz,项目名称:PTVS,代码行数:86,代码来源:FormattingUITests.cs

示例6: SquiggleShowHide

        private static void SquiggleShowHide(string document, Action<PythonVisualStudioApp> test) {
            using (var app = new PythonVisualStudioApp()) {
                UnresolvedImportSquiggleProvider._alwaysCreateSquiggle = true;
                app.OnDispose(() => UnresolvedImportSquiggleProvider._alwaysCreateSquiggle = false);


                var project = app.OpenProject(@"TestData\MissingImport.sln");

                var editorWindows = app.Dte.Windows
                    .OfType<EnvDTE.Window>()
                    .Where(w => w.Kind == "Editor")
                    .ToArray();
                foreach (var w in editorWindows) {
                    w.Close(vsSaveChanges.vsSaveChangesNo);
                }

                var wnd = project.ProjectItems.Item(document).Open();
                wnd.Activate();
                try {
                    test(app);
                } finally {
                    wnd.Close();
                }
            }
        }
开发者ID:omnimark,项目名称:PTVS,代码行数:25,代码来源:EditorTests.cs

示例7: IndentationInconsistencyIgnore

        public void IndentationInconsistencyIgnore() {
            using (var app = new PythonVisualStudioApp()) {
                var options = app.Options;
                var severity = options.IndentationInconsistencySeverity;
                options.IndentationInconsistencySeverity = Severity.Ignore;
                app.OnDispose(() => options.IndentationInconsistencySeverity = severity);

                var project = app.OpenProject(@"TestData\InconsistentIndentation.sln");

                List<IVsTaskItem> items = app.WaitForErrorListItems(0);
                Assert.AreEqual(0, items.Count);
            }
        }
开发者ID:omnimark,项目名称:PTVS,代码行数:13,代码来源:EditorTests.cs

示例8: IndentationInconsistencyError

        public void IndentationInconsistencyError() {
            using (var app = new PythonVisualStudioApp()) {
                var options = app.Options;
                var severity = options.IndentationInconsistencySeverity;
                options.IndentationInconsistencySeverity = Severity.Error;
                app.OnDispose(() => options.IndentationInconsistencySeverity = severity);

                var project = app.OpenProject(@"TestData\InconsistentIndentation.sln");

                var items = app.WaitForErrorListItems(1);
                Assert.AreEqual(1, items.Count);

                VSTASKPRIORITY[] pri = new VSTASKPRIORITY[1];
                ErrorHandler.ThrowOnFailure(items[0].get_Priority(pri));
                Assert.AreEqual(VSTASKPRIORITY.TP_HIGH, pri[0]);
            }
        }
开发者ID:omnimark,项目名称:PTVS,代码行数:17,代码来源:EditorTests.cs

示例9: AutoIndent

        public void AutoIndent() {
            using (var app = new PythonVisualStudioApp()) {
                var options = app.GetService<PythonToolsService>().AdvancedOptions;
                var prevSetting = options.AddNewLineAtEndOfFullyTypedWord;
                app.OnDispose(() => options.AddNewLineAtEndOfFullyTypedWord = prevSetting);
                options.AddNewLineAtEndOfFullyTypedWord = true;

                var project = app.OpenProject(@"TestData\AutoIndent.sln");


                // http://pytools.codeplex.com/workitem/116
                AutoIndentTest(app, project, "def f():\rprint 'hi'\r\rdef inner(): pass←←←←←←←←←←←←←←←←←\r", @"def f():
    print 'hi'

    
    def inner(): pass");

                // http://pytools.codeplex.com/workitem/121
                AutoIndentTest(app, project, "x = {'a': [1, 2, 3],\r\r'b':42}", @"x = {'a': [1, 2, 3],

     'b':42}");

                AutoIndentTest(app, project, "x = {  #comment\r'a': [\r1,\r2,\r3\r],\r\r'b':42\r}", @"x = {  #comment
    'a': [
        1,
        2,
        3
        ],

    'b':42
    }");

                AutoIndentTest(app, project, "if True:\rpass\r\r42\r\r", @"if True:
    pass

42

");

                AutoIndentTest(app, project, "def f():\rreturn\r\r42\r\r", @"def f():
    return

42

");

                AutoIndentTest(app, project, "if True: #fob\rpass\relse: #oar\rpass\r\r42\r\r", @"if True: #fob
    pass
else: #oar
    pass

42

");

                AutoIndentTest(app, project, "if True:\rraise Exception()\r\r42\r\r", @"if True:
    raise Exception()

42

");

                AutoIndentTest(app, project, "while True:\rcontinue\r\r42\r\r", @"while True:
    continue

42

");

                AutoIndentTest(app, project, "while True:\rbreak\r\r42\r\r", @"while True:
    break

42

");
                // http://pytools.codeplex.com/workitem/127
                AutoIndentTest(app, project, "print ('%s, %s' %\r(1, 2))", @"print ('%s, %s' %
       (1, 2))");

                // http://pytools.codeplex.com/workitem/125
                AutoIndentTest(app, project, "def f():\rx = (\r7)\rp", @"def f():
    x = (
        7)
    p");

                AutoIndentTest(app, project, "def f():\rassert False, \\\r'A message'\rp", @"def f():
    assert False, \
        'A message'
    p");

                // other tests...
                AutoIndentTest(app, project, "1 +\\\r2 +\\\r3 +\\\r4 + 5\r", @"1 +\
    2 +\
    3 +\
    4 + 5
");


                AutoIndentTest(app, project, "x = {42 :\r42}\rp", @"x = {42 :
     42}
//.........这里部分代码省略.........
开发者ID:omnimark,项目名称:PTVS,代码行数:101,代码来源:EditorTests.cs


注:本文中的TestUtilities.UI.Python.PythonVisualStudioApp.OnDispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。