Exemplo n.º 1
0
        /// <summary>
        /// Creates a database containing the default modules and any overrides
        /// specified in modules. The overrides will be copied from
        /// TestData\Databases\Vxx, where Vxx is taken from the provided
        /// version number.
        ///
        /// Each tuple in modules specifies the source filename and destination
        /// filename, respectively.
        /// </summary>
        public static MockCompletionDB Create(PythonLanguageVersion version, params Tuple <string, string>[] modules)
        {
            var source1 = PythonTypeDatabase.BaselineDatabasePath;
            var source2 = TestData.GetPath(Path.Combine("TestData", "Databases", version.ToString()));

            Assert.IsTrue(Directory.Exists(source1), "Cannot find " + source1);
            Assert.IsTrue(Directory.Exists(source2), "Cannot find " + source2);

            var db = new MockCompletionDB(TestData.GetTempPath(), version);

            Assert.IsNotNull(db, "Unable to create DB path");
            Console.WriteLine("Creating temporary database at {0}", db.DBPath);

            foreach (var src in Directory.EnumerateFiles(source1, "*.idb"))
            {
                File.Copy(src, Path.Combine(db.DBPath, Path.GetFileName(src)));
            }

            foreach (var mod in modules)
            {
                var src = Path.Combine(source2, mod.Item1 + ".idb");
                Assert.IsTrue(File.Exists(src), "No IDB file for " + mod.Item1);

                Console.WriteLine("Copying {0} from {1} as {2}", mod.Item1, src, mod.Item2);
                File.Copy(src, Path.Combine(db.DBPath, mod.Item2 + ".idb"), true);
                Assert.IsTrue(db.Contains(mod.Item2), "Failed to copy module " + mod.Item1);
            }

            File.WriteAllText(Path.Combine(db.DBPath, "database.ver"),
                              PythonTypeDatabase.CurrentVersion.ToString());

            return(db);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a database containing the default modules and any overrides
        /// specified in modules. The overrides will be copied from
        /// TestData\Databases\Vxx, where Vxx is taken from the provided
        /// version number.
        /// 
        /// Each tuple in modules specifies the source filename and destination
        /// filename, respectively.
        /// </summary>
        public static MockCompletionDB Create(PythonLanguageVersion version, params Tuple<string, string>[] modules) {
            var source1 = PythonTypeDatabase.BaselineDatabasePath;
            var source2 = TestData.GetPath(Path.Combine("TestData", "Databases", version.ToString()));
            Assert.IsTrue(Directory.Exists(source1), "Cannot find " + source1);
            Assert.IsTrue(Directory.Exists(source2), "Cannot find " + source2);

            var db = new MockCompletionDB(TestData.GetTempPath(randomSubPath: true), version);
            Assert.IsNotNull(db, "Unable to create DB path");
            Console.WriteLine("Creating temporary database at {0}", db.DBPath);

            foreach (var src in Directory.EnumerateFiles(source1, "*.idb")) {
                File.Copy(src, Path.Combine(db.DBPath, Path.GetFileName(src)));
            }

            foreach (var mod in modules) {
                var src = Path.Combine(source2, mod.Item1 + ".idb");
                Assert.IsTrue(File.Exists(src), "No IDB file for " + mod.Item1);

                Console.WriteLine("Copying {0} from {1} as {2}", mod.Item1, src, mod.Item2);
                File.Copy(src, Path.Combine(db.DBPath, mod.Item2 + ".idb"), true);
                Assert.IsTrue(db.Contains(mod.Item2), "Failed to copy module " + mod.Item1);
            }

            File.WriteAllText(Path.Combine(db.DBPath, "database.ver"),
                PythonTypeDatabase.CurrentVersion.ToString());

            return db;
        }
Exemplo n.º 3
0
        private static void OSPathImportTest(MockVs vs, MockCompletionDB db) {
            var code = "from ";
            AssertUtil.ContainsAtLeast(GetCompletions(vs, -1, code, db.Factory), "os", "sys");

            code = "from o";
            var completions = GetCompletions(vs, -1, code, db.Factory);
            AssertUtil.ContainsAtLeast(completions, "os");
            AssertUtil.DoesntContain(completions, "sys");

            code = "from os ";
            AssertUtil.ContainsExactly(GetCompletions(vs, -1, code, db.Factory), "import");

            code = "from os import";
            AssertUtil.ContainsExactly(GetCompletions(vs, -1, code, db.Factory), "import");

            code = "from os import ";
            AssertUtil.ContainsAtLeast(GetCompletions(vs, -1, code, db.Factory), "path");

            code = "from os.";
            AssertUtil.ContainsExactly(GetCompletions(vs, -1, code, db.Factory), "path");

            code = "from os.path import ";
            AssertUtil.ContainsAtLeast(GetCompletions(vs, -1, code, db.Factory), "abspath", "relpath");

            var allNames = new HashSet<string>();
            allNames.UnionWith(GetCompletions(vs, -1, "from ntpath import ", db.Factory));
            allNames.UnionWith(GetCompletions(vs, -1, "from posixpath import ", db.Factory));

            code = "from os.path import ";
            AssertUtil.ContainsAtLeast(GetCompletions(vs, -1, code, db.Factory), allNames);
        }