⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pyparsertest.java

📁 Python Development Environment (Python IDE plugin for Eclipse). Features editor, code completion, re
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    
    public void testOnNumarray() {
        if(TestDependent.HAS_NUMARRAY_INSTALLED){
            
            File file = new File(TestDependent.PYTHON_NUMARRAY_PACKAGES);
            parseFilesInDir(file);
            file = new File(TestDependent.PYTHON_NUMARRAY_PACKAGES+"linear_algebra/");
            parseFilesInDir(file);
        }
    }
    
    public void testOnWxPython() {
        if(TestDependent.HAS_WXPYTHON_INSTALLED){
            File file = new File(TestDependent.PYTHON_WXPYTHON_PACKAGES+"wxPython");
            parseFilesInDir(file);
            file = new File(TestDependent.PYTHON_WXPYTHON_PACKAGES+"wx");
            parseFilesInDir(file);
        }
    }

    public void testOnCompleteLib() {
        File file = new File(TestDependent.PYTHON_LIB);
        parseFilesInDir(file);
    }

    /**
     * @param file
     */
    private void parseFilesInDir(File file) {
        assertTrue("Directory "+file+" does not exist", file.exists());
        assertTrue(file.isDirectory());
        File[] files = file.listFiles();
        for (int i = 0; i < files.length; i++) {
            File f = files[i];
            if(f.getAbsolutePath().toLowerCase().endsWith(".py")){
                parseLegalDocStr(REF.getFileContents(f), f);
            }
        }
    }
    
    
//    not removed completely because we may still want to debug it later...
//    public void testOnCsv() {
//    	PyParser.USE_FAST_STREAM = false;
//    	String loc = TestDependent.PYTHON_LIB+"csv.py";
//    	String s = REF.getFileContents(new File(loc));
//    	parseLegalDocStr(s);
//    	
//    	PyParser.USE_FAST_STREAM = true;
//    	loc = TestDependent.PYTHON_LIB+"csv.py";
//    	s = REF.getFileContents(new File(loc));
//    	parseLegalDocStr(s);
//    }
    
    
    public void testOnCgiMod() {
        String s = "dict((day, index) for index, daysRep in enumeratedDays for day in daysRep)";
        parseLegalDocStr(s);
    }
    
    public void testOnCgiMod2() {
        String loc = TestDependent.PYTHON_LIB+"cgi.py";
        String s = REF.getFileContents(new File(loc));
        parseLegalDocStr(s);
    }
    
//    this should really give errors (but is not a priority)
//    public void testErrOnFor() {
//        //ok, it should throw errors in those cases (but that's not so urgent)
//        String s = "foo(x for x in range(10), 100)\n";
//        parseILegalDoc(new Document(s));
//        
//        String s1 = "foo(100, x for x in range(10))\n";
//        parseILegalDoc(new Document(s1));
//        
//    }
    
    public void testOnTestGrammar() {
        String loc = TestDependent.PYTHON_LIB+"test/test_grammar.py";
        String s = REF.getFileContents(new File(loc));
        parseLegalDocStr(s,"(file: test_grammar.py)");
    }
    
    public void testOnTestContextLib() {
        if(TestDependent.HAS_PYTHON_TESTS){
        	String loc = TestDependent.PYTHON_LIB+"test/test_contextlib.py";
	        String s = REF.getFileContents(new File(loc));
	        parseLegalDocStr(s,"(file: test_contextlib.py)");
        }
    }
    
    public void testOnCalendar() {
        String loc = TestDependent.PYTHON_LIB+"hmac.py";
        String s = REF.getFileContents(new File(loc));
        parseLegalDocStr(s);
    }
    
    public void testOnUnittestMod() {
        String loc = TestDependent.PYTHON_LIB+"unittest.py";
        String s = REF.getFileContents(new File(loc));
        parseLegalDocStr(s);
    }
    
    public void testOnCodecsMod() {
        String loc = TestDependent.PYTHON_LIB+"codecs.py";
        String s = REF.getFileContents(new File(loc));
        parseLegalDocStr(s);
    }
    
    public void testOnDocBaseHTTPServer() {
        String loc = TestDependent.PYTHON_LIB+"BaseHTTPServer.py";
        String s = REF.getFileContents(new File(loc));
        parseLegalDocStr(s);
    }
    
    public void testOnDocXMLRPCServerMod() {
        String loc = TestDependent.PYTHON_LIB+"DocXMLRPCServer.py";
        String s = REF.getFileContents(new File(loc));
        parseLegalDocStr(s);
    }
    
    public void testNewImportParser() {
        String s = "" +
        "from a import (b,\n" +
        "            c,\n" +
        "            d)\n" +
        "\n" +
        "\n" +
        "";
        parseLegalDocStr(s);
    }
    
    public void testNewImportParser2() {
        String s = "" +
        "from a import (b,\n" +
        "            c,\n" +
        "            )\n" +
        "\n" +
        "\n" +
        "";
        parseLegalDocStr(s);
    }
    
    public void testNewImportParser3() {
        String s = "" +
        "from a import (b,\n" +
        "            c,,\n" + //err
        "            )\n" +
        "\n" +
        "\n" +
        "";
        parseILegalDoc(new Document(s));
    }
    
    public void testParser() {
        String s = "class C: pass";
        parseLegalDocStr(s);
    }

    public void testEndWithComment() {
        String s = "class C: \n" +
                "    pass\n" +
                "#end\n" +
                "";
        parseLegalDocStr(s);
    }
    
    public void testParser7() {
        String s = "" +
        "if a < (2, 2):\n"+
        "    False, True = 0, 1\n"+
        "\n"+
        "\n";
        parseLegalDocStr(s);
    }
    
    public void testParser8() {
        String s = "" +
"if type(clsinfo) in (types.TupleType, types.ListType):\n"+
"    pass\n"+
"\n"+
"\n"+
"\n";
        parseLegalDocStr(s);
    }
    
    public void testParser2() {
        String s = "" +
        "td = dict()                                                            \n"+
        "                                                                       \n"+
        "for foo in sorted(val for val in td.itervalues() if val[0] == 's'):    \n"+
        "    print foo                                                          \n";
        
        parseLegalDocStr(s);
    }
    
    public void testParser13() throws Exception {
        String s = "plural = lambda : None";
        parseLegalDocStr(s);
        
    }
    
    public void testParser3() {
        String s = "print (x for x in y)";
        
        parseLegalDocStr(s);
    }

    public void testParser4() {
        String s = "print sum(x for x in y)";
        
        parseLegalDocStr(s);
    }
    
    public void testParser5() {
        String s = "print sum(x.b for x in y)";
        
        parseLegalDocStr(s);
    }
    
    public void testParser6() {
        String s = "" +
        "import re\n"+
        "def firstMatch(s,regexList):\n"+
        "    for match in (regex.search(s) for regex in regexList):\n"+
        "        if match: return match\n"+
        "\n"+
        "\n";        
        parseLegalDocStr(s);
    }
    
    
    public void testParser9() {
        String s = "" +
        "a[1,]\n"+
        "a[1,2]\n"+
        "\n"+
        "\n"+
        "\n"+
        "\n";        
        parseLegalDocStr(s);
    }
    
    /**
     * l = [ "encode", "decode" ]
     * 
     * expected beginCols at: 7 and 17
     */
    public void testParser10() {
    	String s = "" +
    	"l = [ \"encode\", \"decode\" ] \n"+
    	"\n";        
    	SimpleNode node = parseLegalDocStr(s);
    	List<ASTEntry> strs = SequencialASTIteratorVisitor.create(node).getAsList(new Class[]{Str.class});
    	assertEquals(7, strs.get(0).node.beginColumn);
    	assertEquals(17, strs.get(1).node.beginColumn);
    }
    
    
    public void testParser11() {
        String s = "" +
        "if True:\n"+        
        "    pass\n"+        
        "elif True:\n"+        
        "    pass\n"+        
        "else:\n"+        
        "    pass\n"+        
        "\n"+        
        "\n";        
        parseLegalDocStr(s);
    }
    
    public void testParser12() {
        String s = "" +
        "m1()\n"+        
        "\n";        
        parseLegalDocStr(s);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -