1 package jep.test;
2 
3 import jep.Interpreter;
4 import jep.JepConfig;
5 import jep.JepException;
6 import jep.SubInterpreter;
7 
8 /**
9  * Tests that a compiled script can be loaded by Jep.runscript()
10  *
11  * Created: May 2017
12  *
13  * @author Ben Steffensmeier
14  * @see "https://github.com/ninia/jep/issues/77"
15  */
16 public class TestCompiledScript {
17 
main(String[] args)18     public static void main(String[] args) throws JepException {
19         Object result = null;
20         JepConfig config = new JepConfig();
21         config.addIncludePaths(".");
22         try (Interpreter interp = new SubInterpreter(config)) {
23             interp.eval("import py_compile");
24             interp.eval(
25                     "py_compile.compile(file='build/testScript.py', cfile='build/testScript.pyc')");
26             interp.eval(null);
27             interp.runScript("build/testScript.pyc");
28             result = interp.getValue("isGood()");
29         }
30         if (!Boolean.TRUE.equals(result)) {
31             throw new IllegalStateException("isGood() returned " + result);
32         }
33     }
34 
35 }
36