Ejemplo n.º 1
0
        public void AnalyzeBadEgg()
        {
            var factories = new[] { InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(new Version(3, 4)) };
            using (var analyzer = new VsProjectAnalyzer(PythonToolsTestUtilities.CreateMockServiceProvider(), factories[0])) {
                analyzer.AnalyzeZipArchiveAsync(TestData.GetPath(@"TestData\BadEgg.egg")).Wait();
                analyzer.WaitForCompleteAnalysis(_ => true);

                // Analysis result must contain the module for the filename inside the egg that is a valid identifier,
                // and no entries for the other filename which is not.
                var moduleNames = analyzer.GetModulesResult(true).Result.Select(x => x.Name);
                AssertUtil.Contains(moduleNames, "module");
                AssertUtil.DoesntContain(moduleNames, "42");
            }
        }
Ejemplo n.º 2
0
        public void LoadAndUnloadModule() {
            var factories = new[] { InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(new Version(3, 3)) };
            using (var analyzer = new VsProjectAnalyzer(PythonToolsTestUtilities.CreateMockServiceProvider(), factories[0], factories)) {
                var m1Path = TestData.GetPath("TestData\\SimpleImport\\module1.py");
                var m2Path = TestData.GetPath("TestData\\SimpleImport\\module2.py");

                var entry1 = analyzer.AnalyzeFile(m1Path) as IPythonProjectEntry;
                var entry2 = analyzer.AnalyzeFile(m2Path) as IPythonProjectEntry;
                analyzer.WaitForCompleteAnalysis(_ => true);

                AssertUtil.ContainsExactly(
                    analyzer.Project.GetEntriesThatImportModule("module1", true).Select(m => m.ModuleName),
                    "module2"
                );

                AssertUtil.ContainsExactly(
                    entry2.Analysis.GetValuesByIndex("x", 0).Select(v => v.TypeId),
                    BuiltinTypeId.Int
                );

                analyzer.UnloadFile(entry1);
                analyzer.WaitForCompleteAnalysis(_ => true);

                // Even though module1 has been unloaded, we still know that
                // module2 imports it.
                AssertUtil.ContainsExactly(
                    analyzer.Project.GetEntriesThatImportModule("module1", true).Select(m => m.ModuleName),
                    "module2"
                );

                AssertUtil.ContainsExactly(
                    entry2.Analysis.GetValuesByIndex("x", 0).Select(v => v.TypeId)
                );

                analyzer.AnalyzeFile(m1Path);
                analyzer.WaitForCompleteAnalysis(_ => true);

                AssertUtil.ContainsExactly(
                    analyzer.Project.GetEntriesThatImportModule("module1", true).Select(m => m.ModuleName),
                    "module2"
                );

                AssertUtil.ContainsExactly(
                    entry2.Analysis.GetValuesByIndex("x", 0).Select(v => v.TypeId),
                    BuiltinTypeId.Int
                );
            }
        }
Ejemplo n.º 3
0
        public void LoadAndUnloadModule() {
            var factories = new[] { InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(new Version(3, 3)) };
            using (var analyzer = new VsProjectAnalyzer(PythonToolsTestUtilities.CreateMockServiceProvider(), factories[0])) {
                var m1Path = TestData.GetPath("TestData\\SimpleImport\\module1.py");
                var m2Path = TestData.GetPath("TestData\\SimpleImport\\module2.py");

                var taskEntry1 = analyzer.AnalyzeFileAsync(m1Path);
                var taskEntry2 = analyzer.AnalyzeFileAsync(m2Path);
                taskEntry1.Wait(CancellationTokens.After5s);
                taskEntry2.Wait(CancellationTokens.After5s);
                var entry1 = taskEntry1.Result;
                var entry2 = taskEntry2.Result;

                var cancel = CancellationTokens.After60s;
                analyzer.WaitForCompleteAnalysis(_ => !cancel.IsCancellationRequested);
                cancel.ThrowIfCancellationRequested();

                var loc = new Microsoft.PythonTools.Parsing.SourceLocation(0, 1, 1);
                AssertUtil.ContainsExactly(
                    analyzer.GetEntriesThatImportModuleAsync("module1", true).Result.Select(m => m.moduleName),
                    "module2"
                );

                AssertUtil.ContainsExactly(
                    analyzer.GetValueDescriptions(entry2, "x", loc),
                    "int"
                );

                analyzer.UnloadFileAsync(entry1).Wait();
                analyzer.WaitForCompleteAnalysis(_ => true);

                // Even though module1 has been unloaded, we still know that
                // module2 imports it.
                AssertUtil.ContainsExactly(
                    analyzer.GetEntriesThatImportModuleAsync("module1", true).Result.Select(m => m.moduleName),
                    "module2"
                );

                AssertUtil.ContainsExactly(
                    analyzer.GetValueDescriptions(entry2, "x", loc)
                );

                analyzer.AnalyzeFileAsync(m1Path).Wait();
                analyzer.WaitForCompleteAnalysis(_ => true);

                AssertUtil.ContainsExactly(
                    analyzer.GetEntriesThatImportModuleAsync("module1", true).Result.Select(m => m.moduleName),
                    "module2"
                );

                AssertUtil.ContainsExactly(
                    analyzer.GetValueDescriptions(entry2, "x", loc),
                    "int"
                );
            }
        }