public void PropertyOfUnknownType() { using (var db = MockCompletionDB.Create(PythonLanguageVersion.V34, "property_of_unknown_type")) { var ptd = db.Database; var module = ptd.GetModule("property_of_unknown_type"); Assert.IsNotNull(module); var cls = module.GetMember(null, "Class"); Assert.IsInstanceOfType(cls, typeof(IPythonType)); var propObj = ((IPythonType)cls).GetMember(null, "no_return"); Assert.IsInstanceOfType(propObj, typeof(IBuiltinProperty)); var prop = (IBuiltinProperty)propObj; // The type is unspecified in the DB, so it should be object Assert.IsNotNull(prop.Type, "Property type should never be null"); Assert.AreEqual(BuiltinTypeId.Object, prop.Type.TypeId, "Property should be of type object"); Assert.AreEqual("property of type object", prop.Description); // Ensure that we are still getting properties at all propObj = ((IPythonType)cls).GetMember(null, "with_return"); Assert.IsInstanceOfType(propObj, typeof(IBuiltinProperty)); prop = (IBuiltinProperty)propObj; Assert.IsNotNull(prop.Type, "Property should not have null type"); Assert.AreEqual("property of type int", prop.Description); } }
public void LayeredDatabase() { using (var db1 = MockCompletionDB.Create(PythonLanguageVersion.V27, "os")) using (var db2 = MockCompletionDB.Create(PythonLanguageVersion.V27, "posixpath")) { Assert.IsNotNull(db1.Database.GetModule("os")); Assert.IsNull(db1.Database.GetModule("posixpath")); var ptd1 = db1.Database; var ptd2 = ptd1.Clone(); ptd2.LoadDatabase(db2.DBPath); Assert.IsNull(ptd1.GetModule("posixpath")); Assert.IsNotNull(ptd2.GetModule("os")); Assert.IsNotNull(ptd2.GetModule("posixpath")); Assert.AreSame(ptd1.GetModule("os"), db1.Database.GetModule("os")); Assert.AreSame(ptd2.GetModule("os"), db1.Database.GetModule("os")); } var factory = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(new Version(2, 7)); using (var db1 = MockCompletionDB.Create(PythonLanguageVersion.V27, "os", "posixpath")) using (var db2 = MockCompletionDB.Create(PythonLanguageVersion.V27, "posixpath")) { var ptd1 = new PythonTypeDatabase(factory, new[] { db1.DBPath, db2.DBPath }); Assert.IsNotNull(ptd1.GetModule("posixpath")); Assert.AreNotSame(ptd1.GetModule("posixpath"), db1.Database.GetModule("posixpath")); Assert.AreNotSame(ptd1.GetModule("posixpath"), db2.Database.GetModule("posixpath")); var ptd2 = new PythonTypeDatabase(factory, new[] { db2.DBPath, db1.DBPath }); Assert.IsNotNull(ptd2.GetModule("posixpath")); Assert.AreNotSame(ptd2.GetModule("posixpath"), db1.Database.GetModule("posixpath")); Assert.AreNotSame(ptd2.GetModule("posixpath"), db2.Database.GetModule("posixpath")); } using (var db1 = MockCompletionDB.Create(PythonLanguageVersion.V27, "os", "posixpath")) using (var db2 = MockCompletionDB.Create(PythonLanguageVersion.V27, "posixpath")) using (var db3 = MockCompletionDB.Create(PythonLanguageVersion.V27, "ntpath")) { var ptd = db1.Database; Assert.AreSame(ptd.GetModule("posixpath"), db1.Database.GetModule("posixpath")); Assert.AreNotSame(ptd.GetModule("posixpath"), db2.Database.GetModule("posixpath")); var ptd2 = ptd.Clone(); ptd2.LoadDatabase(db2.DBPath); Assert.AreNotSame(ptd2.GetModule("posixpath"), ptd.GetModule("posixpath")); var ptd3 = ptd2.Clone(); ptd3.LoadDatabase(db3.DBPath); Assert.IsNotNull(ptd3.GetModule("ntpath")); Assert.IsNull(ptd2.GetModule("ntpath")); } }
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); }
public void FromOSPathImportCompletions3x() { using (var vs = new MockVs()) using (var db = MockCompletionDB.Create(PythonLanguageVersion.V33, "os", "ntpath", "posixpath", "os2emxpath")) { OSPathImportTest(vs, db); } }
public void Invalid2xDatabase() { using (var db = MockCompletionDB.Create(PythonLanguageVersion.V27, // __bad_builtin__ is missing str Tuple.Create("__bad_builtin__", "__builtin__") )) { var ptd = db.Database; Assert.IsNotNull(ptd.GetModule("__builtin__")); var analyzer = db.MakeAnalyzer(); // String type should have been loaded from the default DB. Assert.IsNotNull(analyzer.ClassInfos[BuiltinTypeId.Str]); Assert.IsNotNull(analyzer.ClassInfos[BuiltinTypeId.Bytes]); } }
public void InvalidIronPythonDatabase() { using (var db = MockCompletionDB.Create(PythonLanguageVersion.V27, // __bad_builtin__ is missing str Tuple.Create("__bad_builtin__", "__builtin__") )) { var ptd = db.Database; Assert.IsNotNull(ptd.GetModule("__builtin__")); var factory = new IronPythonInterpreterFactory(); // Explicitly create an IronPythonInterpreter from factory that // will use the database in db.Factory. using (var analyzer = PythonAnalyzer.CreateSynchronously(factory, factory.MakeInterpreter(db.Factory))) { // String type should have been loaded anyway Assert.IsNotNull(analyzer.ClassInfos[BuiltinTypeId.Str]); } } }
public void Invalid3xDatabase() { using (var db = MockCompletionDB.Create(PythonLanguageVersion.V33, // bad_builtins is missing str Tuple.Create("bad_builtins", "builtins") )) { var ptd = db.Database; Assert.IsNotNull(ptd.GetModule("builtins")); var analyzer = db.MakeAnalyzer(); // String type should have been loaded from the default DB. Assert.IsNotNull(analyzer.ClassInfos[BuiltinTypeId.Str]); // String type is the same as unicode, but not bytes. Assert.AreNotEqual(analyzer.Types[BuiltinTypeId.Bytes], analyzer.Types[BuiltinTypeId.Str]); Assert.AreEqual(analyzer.Types[BuiltinTypeId.Unicode], analyzer.Types[BuiltinTypeId.Str]); // String's module name is 'builtins' and not '__builtin__' // because we replace the module name based on the version // despite using the 2.7-based database. Assert.AreEqual("builtins", analyzer.Types[BuiltinTypeId.Str].DeclaringModule.Name); } }
private static void OSPathImportTest(MockVs vs, MockCompletionDB db) { using (var editor = new PythonEditor(vs: vs, factory: db.Factory)) { editor.Text = "from "; AssertUtil.ContainsAtLeast(editor.GetCompletions(-1), "os", "sys"); editor.Text = "from o"; var completions = editor.GetCompletions(-1); AssertUtil.ContainsAtLeast(completions, "os"); AssertUtil.DoesntContain(completions, "sys"); editor.Text = "from os "; AssertUtil.ContainsExactly(editor.GetCompletions(-1), "import"); editor.Text = "from os import"; AssertUtil.ContainsExactly(editor.GetCompletions(-1), "import"); editor.Text = "from os import "; AssertUtil.ContainsAtLeast(editor.GetCompletions(-1), "path"); editor.Text = "from os."; AssertUtil.ContainsExactly(editor.GetCompletions(-1), "path"); editor.Text = "from os.path import "; AssertUtil.ContainsAtLeast(editor.GetCompletions(-1), "abspath", "relpath"); var allNames = new HashSet <string>(); editor.Text = "from ntpath import "; allNames.UnionWith(editor.GetCompletions(-1)); editor.Text = "from posixpath import "; allNames.UnionWith(editor.GetCompletions(-1)); editor.Text = "from os.path import "; AssertUtil.ContainsAtLeast(editor.GetCompletions(-1), allNames); } }