[Pydev-cvs] org.python.pydev/tests/org/python/pydev/editor/codecompletion PythonCompletionWithBuilti
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2006-04-19 19:44:17
|
Update of /cvsroot/pydev/org.python.pydev/tests/org/python/pydev/editor/codecompletion In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22825/tests/org/python/pydev/editor/codecompletion Modified Files: PythonShellTest.java Added Files: PythonCompletionWithBuiltinsTest.java PythonCompletionWithoutBuiltinsTest.java Removed Files: PythonCompletionTestWithBuiltins.java PythonCompletionTestWithoutBuiltins.java Log Message: --- PythonCompletionTestWithBuiltins.java DELETED --- Index: PythonShellTest.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/tests/org/python/pydev/editor/codecompletion/PythonShellTest.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** PythonShellTest.java 16 Jan 2006 17:17:49 -0000 1.22 --- PythonShellTest.java 19 Apr 2006 19:44:14 -0000 1.23 *************** *** 11,14 **** --- 11,15 ---- import org.eclipse.core.runtime.CoreException; + import org.eclipse.jface.text.BadLocationException; import org.python.pydev.core.TestDependent; import org.python.pydev.core.docutils.StringUtils; *************** *** 88,91 **** --- 89,93 ---- return nature.getAstManager().getModulesManager().getCompletePythonPath(); } + public void testGlu() throws IOException, CoreException { --- NEW FILE: PythonCompletionWithBuiltinsTest.java --- /* * Created on 13/08/2005 */ package org.python.pydev.editor.codecompletion; import java.io.File; import java.io.IOException; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.text.BadLocationException; import org.python.pydev.core.TestDependent; import org.python.pydev.editor.codecompletion.revisited.CodeCompletionTestsBase; import org.python.pydev.editor.codecompletion.revisited.modules.CompiledModule; import org.python.pydev.editor.codecompletion.shell.AbstractShell; import org.python.pydev.editor.codecompletion.shell.PythonShell; public class PythonCompletionWithBuiltinsTest extends CodeCompletionTestsBase{ public static void main(String[] args) { try { PythonCompletionWithBuiltinsTest builtins = new PythonCompletionWithBuiltinsTest(); builtins.setUp(); builtins.testGlu(); builtins.tearDown(); junit.textui.TestRunner.run(PythonCompletionWithBuiltinsTest.class); } catch (Exception e) { e.printStackTrace(); } } private static PythonShell shell; /* * @see TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); CompiledModule.COMPILED_MODULES_ENABLED = true; this.restorePythonPath(TestDependent.PYTHON_LIB+"|"+TestDependent.PYTHON_SITE_PACKAGES+"|"+TestDependent.PYTHON_WXPYTHON_PACKAGES, false); codeCompletion = new PyCodeCompletion(); //we don't want to start it more than once if(shell == null){ shell = PythonShellTest.startShell(); } AbstractShell.putServerShell(nature, AbstractShell.COMPLETION_SHELL, shell); } /* * @see TestCase#tearDown() */ protected void tearDown() throws Exception { CompiledModule.COMPILED_MODULES_ENABLED = false; super.tearDown(); AbstractShell.putServerShell(nature, AbstractShell.COMPLETION_SHELL, null); } public void testCompleteImportBuiltin() throws BadLocationException, IOException, Exception{ String s; s = "from datetime import datetime, date, MINYEAR,"; requestCompl(s, s.length(), -1, new String[] { "date", "datetime", "MINYEAR", "MAXYEAR", "timedelta" }); s = "from datetime.datetime import "; requestCompl(s, s.length(), -1, new String[] { "today", "now", "utcnow" }); // Problem here is that we do not evaluate correctly if // met( ddd, // fff, // ccc ) //so, for now the test just checks that we do not get in any sort of //look... s = "" + "class bla(object):pass\n" + "\n"+ "def newFunc(): \n"+ " callSomething( bla.__get#complete here... stack error \n"+ " keepGoing) \n"; //If we improve the parser to get the error above, uncomment line below to check it... //requestCompl(s, s.indexOf('#'), 1, new String[]{"__getattribute__"}); requestCompl(s, s.indexOf('#'), 0, new String[]{}); //check for builtins..1 s = "" + "\n" + ""; requestCompl(s, s.length(), -1, new String[]{"RuntimeError"}); //check for builtins..2 s = "" + "from testlib import *\n" + "\n" + ""; requestCompl(s, s.length(), -1, new String[]{"RuntimeError"}); //check for builtins..3 (builtins should not be available because it is an import request for completions) requestCompl("from testlib.unittest import ", new String[]{"__init__", "anothertest" , "AnotherTest", "GUITest", "guitestcase", "main", "relative", "t", "TestCase", "testcase", "TestCaseAlias" }); } public void testPreferForcedBuiltin() throws BadLocationException, IOException, Exception{ if(TestDependent.HAS_MX_DATETIME){ String s = ""+ "from mx import DateTime\n"+ "DateTime."; requestCompl(s, s.length(), -1, new String[]{"now()"}); } } public void testDeepNested6() throws CoreException, BadLocationException{ String s; s = "" + "from extendable.nested2 import hub\n"+ "hub.c1.f."; requestCompl(s, s.length(), -1, new String[] { "curdir"}); } public void testDeepNested7() throws CoreException, BadLocationException{ String s; s = "" + "from extendable.nested2 import hub\n"+ "hub.c1.f.curdir."; requestCompl(s, s.length(), -1, new String[] { "upper()"}); } public void testDeepNested8() throws CoreException, BadLocationException{ String s; s = "" + "from extendable.nested2 import hub\n"+ "hub.C1.f.altsep."; requestCompl(s, s.length(), -1, new String[] { "upper()"}); } public void testDeepNested9() throws CoreException, BadLocationException{ String s; s = "" + "from extendable.nested2 import hub\n"+ "hub.C1.f.inexistant."; requestCompl(s, s.length(), -1, new String[] { }); } public void testPreferSrc() throws BadLocationException, IOException, Exception{ String s = ""+ "import prefersrc\n"+ "prefersrc."; requestCompl(s, s.length(), -1, new String[]{"PreferSrc"}); } public void testWxPython1() throws BadLocationException, IOException, Exception{ if(TestDependent.HAS_WXPYTHON_INSTALLED){ //we can only test what we have String s = ""+ "from wxPython.wx import *\n"+ "import wx\n"+ "class HelloWorld(wx.App):\n"+ " def OnInit(self):\n"+ " frame = wx.Frame(None,-1,\"hello world\")\n"+ " frame.Show(True)\n"+ " self.SetTopWindow(frame)\n"+ " b=wx.Button(frame,-1,\"Button\")\n"+ " return True\n"+ "app = HelloWorld(0)\n"+ "app.MainLoop()\n"+ "app."; requestCompl(s, s.length(), -1, new String[]{"MainLoop()"}); } } public void testCompleteImportBuiltinReference2() throws BadLocationException, IOException, Exception{ String s; if(TestDependent.HAS_WXPYTHON_INSTALLED){ //we can only test what we have s = "" + "from wx import "; requestCompl(s, s.length(), -1, new String[]{"glcanvas"}); } } public void testGlu() throws IOException, CoreException, BadLocationException { if(TestDependent.HAS_GLU_INSTALLED){ final String s = "from OpenGL import "; requestCompl(s, s.length(), -1, new String[]{"GLU", "GLUT"}); } } public void testCompleteImportBuiltinReference() throws BadLocationException, IOException, Exception{ String s; if(TestDependent.HAS_WXPYTHON_INSTALLED){ //we can only test what we have s = "" + "from wxPython.wx import wxButton\n"+ " \n"+ "wxButton."; requestCompl(s, s.length(), -1, new String[]{"Close()"}); s = "" + "import wxPython\n"+ " \n"+ "wxPython."; requestCompl(s, s.length(), -1, new String[]{"wx"}); } s = "" + "import os\n"+ " \n"+ "os."; File file = new File("tests/pysrc/simpleosimport.py"); assertTrue(file.exists()); assertTrue(file.isFile()); requestCompl(file, s, s.length(), -1, new String[]{"path"}); s = "" + "import os\n"+ " \n"+ "os."; requestCompl(s, s.length(), -1, new String[]{"path"}); if(TestDependent.HAS_QT_INSTALLED){ //we can only test what we have //check for builtins with reference..3 s = "" + "from qt import *\n"+ " \n"+ "q = QLabel() \n"+ "q."; requestCompl(s, s.length(), -1, new String[]{"AlignAuto"}); } //check for builtins with reference..3 s = "" + "from testlib.unittest import anothertest\n"+ "anothertest."; requestCompl(s, s.length(), 2, new String[]{"AnotherTest","t"}); } } --- PythonCompletionTestWithoutBuiltins.java DELETED --- --- NEW FILE: PythonCompletionWithoutBuiltinsTest.java --- /* * Created on Mar 8, 2005 * * @author Fabio Zadrozny */ package org.python.pydev.editor.codecompletion; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.Document; import org.python.pydev.core.IModule; import org.python.pydev.core.TestDependent; import org.python.pydev.core.docutils.PySelection; import org.python.pydev.editor.codecompletion.revisited.CodeCompletionTestsBase; import org.python.pydev.editor.codecompletion.revisited.modules.CompiledModule; /** * This tests the 'whole' code completion, passing through all modules. * * @author Fabio Zadrozny */ public class PythonCompletionWithoutBuiltinsTest extends CodeCompletionTestsBase { public static void main(String[] args) { try { //DEBUG_TESTS_BASE = true; PythonCompletionWithoutBuiltinsTest test = new PythonCompletionWithoutBuiltinsTest(); test.setUp(); test.testDeepNested6(); test.tearDown(); System.out.println("Finished"); junit.textui.TestRunner.run(PythonCompletionWithoutBuiltinsTest.class); } catch (Exception e) { e.printStackTrace(); } catch(Error e){ e.printStackTrace(); } } /* * @see TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); CompiledModule.COMPILED_MODULES_ENABLED = false; this.restorePythonPath(false); codeCompletion = new PyCodeCompletion(); } /* * @see TestCase#tearDown() */ protected void tearDown() throws Exception { CompiledModule.COMPILED_MODULES_ENABLED = true; super.tearDown(); } public void testCompleteImportCompletion() throws CoreException, BadLocationException{ requestCompl("import testl" , "testlib"); requestCompl("from testl" , "testlib"); requestCompl("from testlib import " , new String[]{"__init__", "unittest"}); requestCompl("from testlib import unittest, __in" , new String[]{"__init__"}); requestCompl("from testlib import unittest,__in" , new String[]{"__init__"}); requestCompl("from testlib import unittest ,__in" , new String[]{"__init__"}); requestCompl("from testlib import unittest , __in" , new String[]{"__init__"}); requestCompl("from testlib import unittest , " , new String[]{"__init__", "unittest"}); requestCompl("from testlib.unittest import ", getTestLibUnittestTokens()); requestCompl("from testlib.unittest.testcase.TestCase import assertImagesNotE", new String[]{"assertImagesNotEqual"}); requestCompl("from testlib.unittest.testcase.TestCase import assertBM", new String[]{"assertBMPsNotEqual","assertBMPsEqual"}); } /** * @return */ private String[] getTestLibUnittestTokens() { return new String[]{ "__init__" , "anothertest" , "AnotherTest" , "GUITest" , "guitestcase" , "main" , "relative" , "t" , "TestCase" , "testcase" , "TestCaseAlias" }; } public void testSelfReference() throws CoreException, BadLocationException{ String s; s = "class C: \n" + " def met1(self): \n" + " pass \n" + " \n" + "class B: \n" + " def met2(self): \n" + " self.c = C()\n" + " \n" + " def met3(self): \n" + " self.c."; requestCompl(s, s.length(), -1, new String[] { "met1()"}); } public void testInnerImport() throws CoreException, BadLocationException{ String s; s = "" + "def m1():\n" + " from testlib import unittest\n" + " unittest."; requestCompl(s, s.length(), -1, new String[]{ "AnotherTest" , "GUITest" , "main" , "TestCase" , "testcase" , "TestCaseAlias" //gotten because unittest is actually an __init__, so, gather others that are in the same level , "anothertest" , "guitestcase" , "testcase" }); } public void testSelfReferenceWithTabs() throws CoreException, BadLocationException{ String s; s = "class C:\n" + " def met1(self):\n" + " pass\n" + " \n" + "class B:\n" + " def met2(self):\n" + " self.c = C()\n" + " \n" + " def met3(self):\n" + " self.c."; s = s.replaceAll("\\ \\ \\ \\ ", "\t"); requestCompl(s, s.length(), -1, new String[] { "met1()"}); } public void testClassCompl() throws CoreException, BadLocationException{ String s; s = "" + "class Test:\n" + " classVar = 1\n"+ " def findIt(self):\n"+ " self."; requestCompl(s, s.length(), -1, new String[] { "classVar"}); } public void testInnerCtxt() throws CoreException, BadLocationException{ String s; s = "" + "class Test:\n"+ " def findIt(self):\n"+ " pass\n"+ " \n"+ "def m1():\n"+ " s = Test()\n"+ " s."; requestCompl(s, s.length(), -1, new String[] { "findIt()"}); } public void testDeepNested() throws CoreException, BadLocationException{ String s; s = "" + "from extendable.nested2 import hub\n"+ "hub.c1.a."; requestCompl(s, s.length(), -1, new String[] { "fun()"}); } public void testDeepNested2() throws CoreException, BadLocationException{ String s; s = "" + "from extendable.nested2 import hub\n"+ "hub.c1.b."; requestCompl(s, s.length(), -1, new String[] { "another()"}); } public void testDeepNested3() throws CoreException, BadLocationException{ String s; s = "" + "from extendable.nested2 import hub\n"+ "hub.c1.c."; requestCompl(s, s.length(), -1, new String[] { "another()"}); } public void testDeepNested4() throws CoreException, BadLocationException{ String s; s = "" + "from extendable.nested2 import hub\n"+ "hub.c1.d."; requestCompl(s, s.length(), -1, new String[] { "AnotherTest"}); } public void testDeepNested5() throws CoreException, BadLocationException{ String s; s = "" + "from extendable.nested2 import hub\n"+ "hub.c1.e."; requestCompl(s, s.length(), -1, new String[] { "assertBMPsNotEqual"}); } public void testDeepNested6() throws CoreException, BadLocationException{ String s; s = "" + "from extendable.nested2 import mod2\n"+ "mod2.c1.a."; requestCompl(s, s.length(), -1, new String[] { "fun()"}); } public void testSelfReferenceWithTabs2() throws CoreException, BadLocationException{ String s; s = "" + "class C:\n" + " def met3(self):\n" + " self.COMPLETE_HERE\n" + " \n" + " def met1(self): \n" + " pass \n" + ""; s = s.replaceAll("\\ \\ \\ \\ ", "\t"); int iComp = s.indexOf("COMPLETE_HERE"); s = s.replaceAll("COMPLETE_HERE", ""); requestCompl(s, iComp, -1, new String[] { "met1()"}); } public void testRelativeImport() throws FileNotFoundException, CoreException, BadLocationException{ String file = TestDependent.TEST_PYSRC_LOC+"testlib/unittest/relative/testrelative.py"; String strDoc = "from toimport import "; requestCompl(new File(file), strDoc, strDoc.length(), -1, new String[]{"Test1", "Test2"}); } public void testWildImportRecursive() throws BadLocationException, IOException, Exception{ String s; s = "from testrecwild import *\n" + ""; requestCompl(s, -1, -1, new String[] { "Class1"}); } public void testWildImportRecursive2() throws BadLocationException, IOException, Exception{ String s; s = "from testrecwild2 import *\n" + ""; requestCompl(s, -1, -1, new String[] { "Class2"}); } public void testWildImportRecursive3() throws BadLocationException, IOException, Exception{ String s; s = "from testrec2 import *\n" + ""; requestCompl(s, -1, -1, new String[] { "Leaf"}); } public void testProperties() throws BadLocationException, IOException, Exception{ String s; s = "class C:\n" + " \n" + " properties.create(test = 0)\n" + " \n" + "c = C."; requestCompl(s, -1, -1, new String[] { "test"}); } public void testImportMultipleFromImport() throws BadLocationException, IOException, Exception{ String s; s = "import testlib.unittest.relative\n" + ""; requestCompl(s, -1, -1, new String[] { "testlib","testlib.unittest","testlib.unittest.relative"}); } public void testImportMultipleFromImport2() throws BadLocationException, IOException, Exception{ String s; s = "import testlib.unittest.relative\n" + "testlib."; requestCompl(s, -1, 0, new String[] { }); } public void testNestedImports() throws BadLocationException, IOException, Exception{ String s; s = "from extendable import nested\n"+ "print nested.NestedClass."; requestCompl(s, -1, 1, new String[] { "nestedMethod()" }); } public void testSameName() throws BadLocationException, IOException, Exception{ String s; s = "from extendable.namecheck import samename\n"+ "print samename."; requestCompl(s, -1, 1, new String[] { "method1()" }); } public void testSameName2() throws BadLocationException, IOException, Exception{ String s; s = "from extendable import namecheck\n"+ "print namecheck.samename."; requestCompl(s, -1, 1, new String[] { "method1()" }); } public void testCompositeImport() throws BadLocationException, IOException, Exception{ String s; s = "import xml.sax\n"+ "print xml.sax."; requestCompl(s, -1, -1, new String[] { "default_parser_list" }); } public void testIsInGlobalTokens() throws BadLocationException, IOException, Exception{ IModule module = nature.getAstManager().getModule("testAssist.__init__", nature, true); assertTrue(module.isInGlobalTokens("assist.ExistingClass.existingMethod", nature)); } public void testGetActTok(){ String strs[]; strs = PySelection.getActivationTokenAndQual(new Document(""), 0); assertEquals("", strs[0]); assertEquals("", strs[1]); strs = PySelection.getActivationTokenAndQual(new Document("self.assertEquals( DECAY_COEF, t.item(0, C).text())"), 42); assertEquals("" , strs[0]); assertEquals("C", strs[1]); strs = PySelection.getActivationTokenAndQual(new Document("self.assertEquals( DECAY_COEF, t.item(0,C).text())"), 41); assertEquals("" , strs[0]); assertEquals("C", strs[1]); strs = PySelection.getActivationTokenAndQual(new Document("m = met(self.c, self.b)"), 14); assertEquals("self." , strs[0]); assertEquals("c", strs[1]); strs = PySelection.getActivationTokenAndQual(new Document("[a,b].ap"), 8); assertEquals("list." , strs[0]); assertEquals("ap", strs[1]); strs = PySelection.getActivationTokenAndQual(new Document("{a:1,b:2}.ap"), 12); assertEquals("dict." , strs[0]); assertEquals("ap", strs[1]); strs = PySelection.getActivationTokenAndQual(new Document("''.ap"), 5); assertEquals("str." , strs[0]); assertEquals("ap", strs[1]); strs = PySelection.getActivationTokenAndQual(new Document("\"\".ap"), 5); assertEquals("str." , strs[0]); assertEquals("ap", strs[1]); strs = PySelection.getActivationTokenAndQual(new Document("ClassA.someMethod.ap"), 20); assertEquals("ClassA.someMethod." , strs[0]); assertEquals("ap", strs[1]); strs = PySelection.getActivationTokenAndQual(new Document("ClassA.someMethod().ap"), 22); assertEquals("ClassA.someMethod()." , strs[0]); assertEquals("ap", strs[1]); strs = PySelection.getActivationTokenAndQual(new Document("ClassA.someMethod( a, b ).ap"), 28); assertEquals("ClassA.someMethod()." , strs[0]); assertEquals("ap", strs[1]); strs = PySelection.getActivationTokenAndQual(new Document("foo.bar"), 2); assertEquals("" , strs[0]); assertEquals("fo", strs[1]); strs = PySelection.getActivationTokenAndQual(new Document("foo.bar"), 2, false); assertEquals("" , strs[0]); assertEquals("fo", strs[1]); strs = PySelection.getActivationTokenAndQual(new Document("foo.bar"), 2, true); assertEquals("" , strs[0]); assertEquals("foo", strs[1]); strs = PySelection.getActivationTokenAndQual(new Document("foo.bar "), 2, true); assertEquals("" , strs[0]); assertEquals("foo", strs[1]); strs = PySelection.getActivationTokenAndQual(new Document("foo.bar "), 5, true); assertEquals("foo.", strs[0]); assertEquals("bar", strs[1]); strs = PySelection.getActivationTokenAndQual(new Document("foo.bar "), 100, true); //out of the league assertEquals("", strs[0]); assertEquals("", strs[1]); String importsTipperStr = PyCodeCompletion.getImportsTipperStr(new Document("from coilib.decorators import "), 30); assertEquals("coilib.decorators" , importsTipperStr); } /** * @throws BadLocationException * @throws CoreException * */ public void testFor() throws CoreException, BadLocationException { String s; s = "" + "for event in a: \n" + " print event \n" + " \n" + "event."; try { requestCompl(s, s.length(), -1, new String[] {}); } catch (StackOverflowError e) { throw new RuntimeException(e); } } } |