Esempio n. 1
0
        public virtual void SyntaxHighlightingRaiseException()
        {
            using (var interactive = Prepare())
                using (var newClassifications = new AutoResetEvent(false)) {
                    const string code = "raise Exception()";
                    interactive.Classifier.ClassificationChanged += (s, e) => newClassifications.SetIfNotDisposed();

                    interactive.SubmitCode(code);

                    interactive.WaitForText(
                        ">" + code,
                        "Traceback (most recent call last):",
                        "  File \"<" + ((PythonReplWindowProxySettings)interactive.Settings).SourceFileName + ">\", line 1, in <module>",
                        "Exception",
                        ">"
                        );

                    var snapshot = interactive.TextView.TextBuffer.CurrentSnapshot;
                    var span     = new SnapshotSpan(snapshot, new Span(0, snapshot.Length));
                    Assert.IsTrue(newClassifications.WaitOne(10000), "Timed out waiting for classification");
                    var classifications = interactive.Classifier.GetClassificationSpans(span);
                    foreach (var c in classifications)
                    {
                        Console.WriteLine("{0} ({1})", c.Span.GetText(), c.ClassificationType.Classification);
                    }

                    Assert.AreEqual(classifications[0].ClassificationType.Classification, PredefinedClassificationTypeNames.Keyword);
                    Assert.AreEqual(classifications[1].ClassificationType.Classification, PredefinedClassificationTypeNames.Identifier);
                    Assert.AreEqual(classifications[2].ClassificationType.Classification, "Python grouping");

                    Assert.AreEqual(classifications[0].Span.GetText(), "raise");
                    Assert.AreEqual(classifications[1].Span.GetText(), "Exception");
                    Assert.AreEqual(classifications[2].Span.GetText(), "()");
                }
        }
Esempio n. 2
0
        public void ShouldWarnOnRun()
        {
            var sln = Generator.Project(
                "HelloWorld",
                ProjectGenerator.Compile("app", "print \"hello\"")
                ).Generate();

            using (var vs = sln.ToMockVs())
                using (var analyzerChanged = new AutoResetEvent(false))
                {
                    var project = vs.GetProject("HelloWorld").GetPythonProject();
                    project.ProjectAnalyzerChanged += (s, e) => analyzerChanged.SetIfNotDisposed();

                    var uiThread     = (UIThreadBase)project.GetService(typeof(UIThreadBase));
                    var interpreters = ((IComponentModel)project.GetService(typeof(SComponentModel)))
                                       .GetService <IInterpreterRegistryService>()
                                       .Interpreters;

                    var v27           = interpreters.Where(x => x.Configuration.Id == "Global|PythonCore|2.7-32").First();
                    var v34           = interpreters.Where(x => x.Configuration.Id == "Global|PythonCore|3.4-32").First();
                    var interpOptions = (UIThreadBase)project.GetService(typeof(IComponentModel));

                    uiThread.Invoke(() =>
                    {
                        project.AddInterpreter(v27.Configuration.Id);
                        project.AddInterpreter(v34.Configuration.Id);
                    });

                    project.SetInterpreterFactory(v27);
                    Assert.IsTrue(analyzerChanged.WaitOne(10000), "Timed out waiting for analyzer change #1");
                    uiThread.Invoke(() => project.GetAnalyzer()).WaitForCompleteAnalysis(_ => true);
                    Assert.IsFalse(project.ShouldWarnOnLaunch, "Should not warn on 2.7");

                    project.SetInterpreterFactory(v34);
                    Assert.IsTrue(analyzerChanged.WaitOne(10000), "Timed out waiting for analyzer change #2");
                    uiThread.Invoke(() => project.GetAnalyzer()).WaitForCompleteAnalysis(_ => true);
                    Assert.IsTrue(project.ShouldWarnOnLaunch, "Expected warning on 3.4");

                    project.SetInterpreterFactory(v27);
                    Assert.IsTrue(analyzerChanged.WaitOne(10000), "Timed out waiting for analyzer change #3");
                    uiThread.Invoke(() => project.GetAnalyzer()).WaitForCompleteAnalysis(_ => true);
                    Assert.IsFalse(project.ShouldWarnOnLaunch, "Expected warning to go away on 2.7");
                }
        }