PythonFileAnalyzer implements FileAnalyzer { @Override public Map<ConstructId, Construct> getConstructs() throws FileAnalysisException { if (this.constructs == null) { analyzer = PythonFileAnalyzer.createAnalyzer(this.file); analyzer.analyze(this.file); this.constructs = analyzer.getConstructs(); } return analyzer.getConstructs(); }  @Override String[] getSupportedFileExtensions(); @Override boolean canAnalyze(File _file); @Override void analyze(final File _file); @Override Map<ConstructId, Construct> getConstructs(); @Override boolean containsConstruct(ConstructId _id); @Override Construct getConstruct(ConstructId _id); @Override boolean hasChilds(); @Override Set<FileAnalyzer> getChilds(boolean _recursive); static PythonId getModule(File _file); static FileAnalyzer createAnalyzer(final File _file); static FileAnalyzer createAnalyzer(InputStream _is);  }
@Test public void testPythonFilesInTestapp() throws FileAnalysisException { final FileAnalyzer f1 = FileAnalyzerFactory.buildFileAnalyzer( new File("src/test/resources/testapp/foo/hello_world.py")); final Map<ConstructId, Construct> c1 = f1.getConstructs(); assertEquals(2, c1.size()); final FileAnalyzer f2 = FileAnalyzerFactory.buildFileAnalyzer( new File("src/test/resources/testapp/foo/func_hw.py")); final Map<ConstructId, Construct> c2 = f2.getConstructs(); assertEquals(4, c2.size()); final FileAnalyzer f3 = FileAnalyzerFactory.buildFileAnalyzer( new File("src/test/resources/testapp/foo/class_hw.py")); final Map<ConstructId, Construct> c3 = f3.getConstructs(); assertEquals(12, c3.size()); final PythonId pack = new PythonId(null, PythonId.Type.PACKAGE, "foo"); final PythonId modu = new PythonId(pack, PythonId.Type.MODULE, "class_hw"); final PythonId func = new PythonId(modu, PythonId.Type.FUNCTION, "func_with_class(arg)"); final PythonId clas = new PythonId(func, PythonId.Type.CLASS, "class_in_func()"); final PythonId meth = new PythonId(clas, PythonId.Type.METHOD, "method_of_class_in_func(self,something)"); assertTrue(c3.containsKey(pack)); assertTrue(c3.containsKey(modu)); assertTrue(c3.containsKey(func)); assertTrue(c3.containsKey(clas)); assertTrue(c3.containsKey(meth)); }
@Test public void testPythonFilesInTinypy() throws FileAnalysisException { final FileAnalyzer f3 = FileAnalyzerFactory.buildFileAnalyzer( new File("src/test/resources/tiny_py_interpreter/tinypy/runtime/Errors.py")); final Map<ConstructId, Construct> c3 = f3.getConstructs(); assertEquals(15, c3.size()); }
@Test public void testPythonFileWithAsync() throws FileAnalysisException { final FileAnalyzer f3 = FileAnalyzerFactory.buildFileAnalyzer(new File("src/test/resources/corecffi.py")); final Map<ConstructId, Construct> c3 = f3.getConstructs(); final PythonId modu = new PythonId(null, PythonId.Type.MODULE, "corecffi"); final PythonId func = new PythonId(modu, PythonId.Type.FUNCTION, "send(self)"); assertFalse(c3.containsKey(func)); }