EMMA Coverage Report (generated Tue Aug 23 05:57:12 CDT 2011)
[all classes][felix.io]

COVERAGE SUMMARY FOR SOURCE FILE [PythonExecutor.java]

nameclass, %method, %block, %line, %
PythonExecutor.java100% (1/1)86%  (6/7)94%  (48/51)88%  (15/17)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PythonExecutor100% (1/1)86%  (6/7)94%  (48/51)88%  (15/17)
PythonExecutor (): void 0%   (0/1)0%   (0/3)0%   (0/2)
PythonExecutor (String): void 100% (1/1)100% (6/6)100% (3/3)
execSingle (String): void 100% (1/1)100% (5/5)100% (2/2)
get (String): PyObject 100% (1/1)100% (5/5)100% (1/1)
prepare (String): void 100% (1/1)100% (20/20)100% (5/5)
run (): void 100% (1/1)100% (6/6)100% (2/2)
set (String, PyObject): void 100% (1/1)100% (6/6)100% (2/2)

1package felix.io;
2 
3import java.util.Arrays;
4 
5import org.python.core.PyCode;
6import org.python.core.PyInteger;
7import org.python.core.PyObject;
8import org.python.util.PythonInterpreter;
9 
10/**
11 * Class for executing python code (using Jython). 
12 * @author Ce Zhang
13 *
14 */
15public class PythonExecutor {
16 
17        /**
18         * pycode
19         */
20        PyCode pycode;
21        
22        /**
23         * python interpreter
24         */
25        PythonInterpreter interp;
26        
27        /**
28         * Prepares given script for execution.
29         * @param script
30         */
31        public void prepare(String script){
32                interp = new PythonInterpreter();
33                pycode = interp.compile(script);
34                
35                interp.exec("def felixio_push(*columns):\n" + 
36                    "\tif(len(columns) == 0):\n"+
37                    "\t\t_felix_donotusemyname_outkey.append('')\n" + 
38                    "\telse:\n" +
39                    "\t\t_felix_donotusemyname_outkey.append(columns[0].replace('\\\\','\\\\\\\\').replace('\\t','\\\\t').replace('\\n', '\\\\n').replace('\\r', '\\\\r'))\n" +
40                    "\t_felix_donotusemyname_outvalue.append('\t'.join(i.__str__().replace('\\\\','\\\\\\\\').replace('\\t','\\\\t').replace('\\n', '\\\\n').replace('\\r', '\\\\r') for i in columns[1:]))\n");
41    
42                interp.exec("def felixio_collect(k, v):\n" + 
43                "\t_felix_donotusemyname_outkey.append(k)\n"+
44                "\t_felix_donotusemyname_outvalue.append(v)");
45                
46        }
47        
48        /**
49         * Returns given variable.
50         * @param variable
51         * @return
52         */
53        public PyObject get(String variable){
54                return interp.get(variable);
55        }
56        
57        /**
58         * Sets given variable.
59         * @param name
60         * @param value
61         */
62        public void set(String name, PyObject value){
63                interp.set(name, value);
64        }
65        
66        /**
67         * Execuates given script.
68         * @param script
69         */
70        public void execSingle(String script){
71                interp.exec(script);
72        }
73 
74        /**
75         * The constructor.
76         */
77        public PythonExecutor(){
78        }
79        
80        /**
81         * The constructor with script.
82         * @param script
83         */
84        public PythonExecutor(String script){
85                this.prepare(script);
86        }
87        
88        /**
89         * Excecutes python script.
90         */
91        public void run(){
92                
93                interp.exec(pycode);
94                
95        }
96        
97        /**
98         * Main test method.
99         * @param args
100         * @throws Exception
101         */
102        /*
103        public static void main(String[] args) throws Exception{
104                
105                PythonExecutor pe = new PythonExecutor();
106                pe.prepare("print sys");
107                
108                pe.execSingle("import sys");
109                
110                for(int i=0;i<10000;i++){
111                        pe.run();
112                }        
113        }
114        */
115        
116}

[all classes][felix.io]
EMMA 2.0.5312 EclEmma Fix 2 (C) Vladimir Roubtsov