コード例 #1
0
ファイル: CompletionDBTest.cs プロジェクト: sadapple/PTVS
        public void CheckObsoleteGenerateFunction()
        {
            var path = PythonPaths.Versions.LastOrDefault(p => p != null && p.IsCPython);

            path.AssertInstalled();

            var factory = InterpreterFactoryCreator.CreateInterpreterFactory(new InterpreterFactoryCreationOptions {
                Id = path.Id,
                LanguageVersion           = path.Version.ToVersion(),
                Description               = "Test Interpreter",
                Architecture              = path.Isx64 ? ProcessorArchitecture.Amd64 : ProcessorArchitecture.X86,
                LibraryPath               = path.LibPath,
                PrefixPath                = path.PrefixPath,
                InterpreterPath           = path.InterpreterPath,
                WatchLibraryForNewModules = false
            });

            var tcs        = new TaskCompletionSource <int>();
            var beforeProc = Process.GetProcessesByName("Microsoft.PythonTools.Analyzer");

            var request = new PythonTypeDatabaseCreationRequest {
                Factory       = factory,
                OutputPath    = TestData.GetTempPath(randomSubPath: true),
                SkipUnchanged = true,
                OnExit        = tcs.SetResult
            };

            Console.WriteLine("OutputPath: {0}", request.OutputPath);

#pragma warning disable 618
            PythonTypeDatabase.Generate(request);
#pragma warning restore 618

            int expected = 0;

            if (!tcs.Task.Wait(TimeSpan.FromMinutes(1.0)))
            {
                var proc = Process.GetProcessesByName("Microsoft.PythonTools.Analyzer")
                           .Except(beforeProc)
                           .ToArray();

                // Ensure we actually started running
                Assert.AreNotEqual(0, proc.Length, "Process is not running");

                expected = -1;

                // Kill the process
                foreach (var p in proc)
                {
                    Console.WriteLine("Killing process {0}", p.Id);
                    p.Kill();
                }

                Assert.IsTrue(tcs.Task.Wait(TimeSpan.FromMinutes(1.0)), "Process did not die");
            }

            Assert.AreEqual(expected, tcs.Task.Result, "Incorrect exit code");
        }
コード例 #2
0
        public void CheckObsoleteGenerateFunction()
        {
            var path = PythonPaths.Versions.LastOrDefault(p => p != null && p.IsCPython);

            path.AssertInstalled();

            var factory = InterpreterFactoryCreator.CreateInterpreterFactory(path.Configuration) as PythonInterpreterFactoryWithDatabase;

            if (factory == null)
            {
                Assert.Inconclusive("Test requires PythonInterpreterFactoryWithDatabase");
            }

            var tcs        = new TaskCompletionSource <int>();
            var beforeProc = Process.GetProcessesByName("Microsoft.PythonTools.Analyzer");

            var request = new PythonTypeDatabaseCreationRequest {
                Factory       = factory,
                OutputPath    = TestData.GetTempPath(),
                SkipUnchanged = true,
                OnExit        = tcs.SetResult
            };

            Console.WriteLine("OutputPath: {0}", request.OutputPath);

#pragma warning disable 618
            PythonTypeDatabase.Generate(request);
#pragma warning restore 618

            int expected = 0;

            if (!tcs.Task.Wait(TimeSpan.FromMinutes(1.0)))
            {
                var proc = Process.GetProcessesByName("Microsoft.PythonTools.Analyzer")
                           .Except(beforeProc)
                           .ToArray();

                // Ensure we actually started running
                Assert.AreNotEqual(0, proc.Length, "Process is not running");

                expected = -1;

                // Kill the process
                foreach (var p in proc)
                {
                    Console.WriteLine("Killing process {0}", p.Id);
                    p.Kill();
                }

                Assert.IsTrue(tcs.Task.Wait(TimeSpan.FromMinutes(1.0)), "Process did not die");
            }

            Assert.AreEqual(expected, tcs.Task.Result, "Incorrect exit code");
        }
コード例 #3
0
        /// <summary>
        /// Regenerates the database for this environment. If the base
        /// interpreter needs regenerating, it will also be regenerated.
        /// </summary>
        public override void GenerateDatabase(GenerateDatabaseOptions options, Action <int> onExit = null)
        {
            if (!Directory.Exists(Configuration.LibraryPath))
            {
                return;
            }

            var req = new PythonTypeDatabaseCreationRequest {
                Factory       = this,
                OutputPath    = DatabasePath,
                SkipUnchanged = options.HasFlag(GenerateDatabaseOptions.SkipUnchanged)
            };

            req.ExtraInputDatabases.Add(_base.DatabasePath);

            _baseHasRefreshed = false;

            if (_base.IsCurrent)
            {
                // The App database is already up to date, so start analyzing
                // the User database immediately.
                base.GenerateDatabase(req, onExit);
            }
            else
            {
                // The App database needs to be updated, so start both and wait
                // for the base to finish before analyzing User.

                // Specifying our base interpreter as 'WaitFor' allows the UI to
                // forward progress and status messages to the user, even though
                // the factory is not visible.
                req.WaitFor = _base;

                // Because the underlying analysis of the standard library has
                // changed, we must reanalyze the entire database.
                req.SkipUnchanged = false;

                // Clear out the existing base database, since we're going to
                // need to reload it again. This also means that when
                // NewDatabaseAvailable is raised, we are expecting it and won't
                // incorrectly set _baseHasRefreshed to true again.
                _baseDb = null;

                // Start our analyzer first, since we will wait up to a minute
                // for the base analyzer to start (which may cause a one minute
                // delay if it completes before we start, but that is unlikely).
                base.GenerateDatabase(req, onExit);
                _base.GenerateDatabase(GenerateDatabaseOptions.SkipUnchanged);
            }
        }